Created
August 9, 2011 15:05
-
-
Save fronx/1134299 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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