From: Sylvester Keil Date: 2012-09-05T22:37:19+09:00 Subject: Re: best coding for limiting a value On Sep 4, 2012, at 10:13 PM, Regis d'Aubarede wrote: > A) result=value max ? max : value) > > B) > result=value > if value < min then result= min end > if value > max then result= max end > > C) > [min,max,value].sort[1] For what its worth, I've often used a variation of A in Ruby like this: [[lower, value].max, upper].min It will obviously not be faster but perhaps easier to understand for some. Overall I think I'd prefer solution C now. Having said that, an Array#median method would be great in this case: [min, max, value].median