Skip to content

Instantly share code, notes, and snippets.

@mwmitchell
Created May 18, 2009 14:16
Show Gist options
  • Save mwmitchell/113503 to your computer and use it in GitHub Desktop.
Save mwmitchell/113503 to your computer and use it in GitHub Desktop.
# number helper for limiting a number within a given range
class Fixnum
def limit(range)
return range.min if self < range.min
return range.max if self > range.max
self
end
end
puts true == (1 == -1998.limit(1..100))
puts true == (100 == 1998.limit(1..100))
puts true == (50 == 50.limit(1..100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment