On 9/2/06, Phrogz <gavin / refinery.com> wrote:
> > Ternary operators are inherently evil whenever nested, although a bit
> > more terse in the good term when used as a single expression.
>
> The one exception I would list is something like a chained comparison.
> For example, a JavaScript implementation of the spaceship operator:
>
> result = a>b ? 1 : a<b ? -1 : 0
>
> As with all things, beauty is in the eye of the beholder, but I find
> that "readable" and certainly nicer than:
>
> result = if a>b
>   1
> elsif a<b
>   -1
> else
>   0
> end

I like the "case true" idiom here:

result = case true
when a == b: 0
when a < b  : 1
when a > b  : -1
end

martin