Project

General

Profile

Actions

Patch #44759

open

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 about 19 hours ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Code cleanup/refactoring

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

No data to display

Actions

Also available in: PDF Atom