method

clamp

Importance_1
v2_4_6 - Show latest stable - 0 notes - Class: Comparable
clamp(p1, p2) public

Returns min if obj <=> min is less than zero, max if obj <=> max is greater than zero and obj otherwise.

12.clamp(0, 100)         #=> 12
523.clamp(0, 100)        #=> 100
-3.123.clamp(0, 100)     #=> 0

'd'.clamp('a', 'f')      #=> 'd'
'z'.clamp('a', 'f')      #=> 'f'
Show source
Register or log in to add new notes.