Project

General

Profile

Actions

Patch #44759

closed

Use Comparable#clamp to limit the number of rows in the description and notes fields

Patch #44759: Use Comparable#clamp to limit the number of rows in the description and notes fields

Added by Go MAEDA 18 days ago. Updated 17 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Code cleanup/refactoring
Target version:

Description

The number of rows in the issue description field and the notes field of the journal edit form is limited with nested Array#max and Array#min:

[[10, @issue.description.to_s.length / 50].max, 20].min

This code dates back to 2006-2008. At that time, Ruby did not provide a method for limiting a value to a range. Comparable#clamp, which was introduced in Ruby 2.4 released in 2016, allows the same limit to be written more simply.

The attached patch replaces these expressions with Comparable#clamp:

(@issue.description.to_s.length / 50).clamp(10, 20)

Unlike the original code, it does not create temporary arrays, and both the lower and upper limits are visible at a glance.


Files

Updated by Go MAEDA 17 days ago Actions #1

  • Status changed from New to Closed
  • Assignee set to Go MAEDA

Committed the patch in r25469.

Updated by Go MAEDA 17 days ago Actions #2

  • Target version changed from Candidate for next major release to 7.1.0
Actions

Also available in: PDF Atom