Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write down these three cases in a more elegant way?

Is it possible to make this code more compact? Am I missing anything here?

    if value < min_rate
      min_rate
    elsif value > max_rate
      max_rate
    else
      value
    end
like image 753
Nikolay Shebanov Avatar asked Nov 09 '12 14:11

Nikolay Shebanov


1 Answers

Here's something completely different:

[min_rate, value, max_rate].sort[1]
like image 171
Mark Thomas Avatar answered Nov 15 '22 04:11

Mark Thomas