Created
April 7, 2016 00:50
-
-
Save swrobel/377f243d9b1ffa51bfd7b3c656332a6e to your computer and use it in GitHub Desktop.
Return a range that is bounded by min & max given, in Ruby
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
def range_within_bounds(range, min, max) | |
min ||= range.min | |
max ||= range.max | |
[range.min, min].max .. [range.max, max].min | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment