Ruby Tips

clamp

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

99.clamp(1,100) # => 99 

101.clamp(1,100) # => 100 

0.clamp(1,100) # => 1

Ruby Tips - a simple ruby tip generator RubyTips.dev

Refresh the page to generate a new tip. Or just click here

Built by @zayneabraham

RubyTips - A random Ruby tip generator | Product Hunt Embed