What about:
case (1 == 2)
when true:
p 'true'
when false:
p 'false'
end
If you don't like the ternary operator the above syntax is pretty clear.
Roy
Ernest Micklei wrote:
> Hi,
>
> For a long time I have been programming Smalltalk.
> Recently, Ruby "got me" and I was wondering how the
> famous ifTrue:ifFalse: could be added to the System.
>
> 1 = 2
> ifTrue:
> [Transcript show: "true!" ]
> ifFalse:
> [Transcript show: "false!"]
>
> So at least the following works but I was hoping that it would have the
> same elegance. "proc" was needed to create a real block instance.
>
> ------------------
> def true.ifTrue_ifFalse(trueBlock , falseBlock)
> trueBlock.call
> end
>
> def false.ifTrue_ifFalse(trueBlock , falseBlock)
> falseBlock.call
> end
>
> (1==2).ifTrue_ifFalse(
> proc { p "true!"},
> proc { p "false!"}
> )
>
> (1!=2).ifTrue_ifFalse(
> proc { p "true!"},
> proc { p "false!"}
> )
>
>