Skip to content

Instantly share code, notes, and snippets.

@fronx
Created August 9, 2011 15:05
Show Gist options
  • Select an option

  • Save fronx/1134299 to your computer and use it in GitHub Desktop.

Select an option

Save fronx/1134299 to your computer and use it in GitHub Desktop.
class Range
def crop(value)
value < min ? min : value > max ? max : value
end
end
class Foobar
MINIMUM_VALUE = 10
MAXIMUM_VALUE = 32
def self.crop(value)
(MINIMUM_VALUE..MAXIMUM_VALUE).crop(value)
end
end
puts Foobar.crop(34) #=> 32
puts Foobar.crop(8) #=> 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment