Skip to content

Instantly share code, notes, and snippets.

@swrobel
Created April 7, 2016 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swrobel/377f243d9b1ffa51bfd7b3c656332a6e to your computer and use it in GitHub Desktop.
Save swrobel/377f243d9b1ffa51bfd7b3c656332a6e to your computer and use it in GitHub Desktop.
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
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment