From: Robert Klemme Date: 2008-10-24T21:12:11+09:00 Subject: Re: Bound macro in ruby 2008/10/24 Me Me : > thanks for answering: > > in my case it's something I can easy implement with if-clause, but I > wanted to know if this could be done in one single line > > def bound(min, value, max) > > if(value > max) > return max > end > > if(value < min) > return min > end > > return value > > end irb(main):001:0> def BOUND(min,val,max) val >=max ? max : val < min ? min : val end => nil irb(main):002:0> BOUND(10,0,100) => 10 irb(main):003:0> irb(main):004:0* BOUND(10,200,100) => 100 irb(main):005:0> BOUND(10,150,100) => 100 irb(main):006:0> BOUND(10,50,100) => 50 Cheers robert -- remember.guy do |as, often| as.you_can - without end