class Fixnum
  def clip_to range
    r = range.first < range.last ? range : (range.last)..(range.first)
    return [ [ r.min, self ].max, r.max ].min
  end
end

Leave a Comment

Enclose code in <code lang="ruby"></code> if you care.
Preview your comment using the button below.