From: Brian Candler Date: 2008-10-24T22:12:59+09:00 Subject: Re: Bound macro in ruby Me Me wrote: > I though it was something already implemented inside ruby If it existed, I would expect to find it as Range#clip or something like that. But I don't think it does. class Range def clip(v) v < first ? first : v > last ? last : v end end p (1..10).clip(5) # 5 p (10..100).clip(5) # 10 (different to your original post??) p (1..10).clip(50) # 10 It wouldn't surprise me if something like this existed in the facets library though. > I guess the same for MIN, MAX irb(main):001:0> [20,40].min => 20 irb(main):002:0> [20,40,30].min => 20 irb(main):003:0> [20,40,30].max => 40 -- Posted via http://www.ruby-forum.com/.