Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Return a range that is bounded by min & max given, in Ruby
def range_within_bounds(range, min, max)
min ||= range.min
max ||= range.max
[range.min, min].max .. [range.max, max].min
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment