Trys
7/11/2008 4:25:00 PM
Chris Chris wrote:
> Hi,
>
> a simple question, however I did not find an answer for this:
>
> How can I put a statement like
>
> if 5 == 5
> puts '5'
> end
>
> in one line?
>
> Just writing them all statements together in one line didn't work,
> and a syntax like if 5 == 5 {puts '5'} end didn't either.
AFAIK, you can't use {} brackets to mark block for "if" statement, so
anything with them won't work.
"If" uses "then" to mark beginning of its block and ends it with usual
"end".
if 5 == 5 then
puts '5'
end
But you can omit "then" if you have multiple lines:
if 5 == 5
puts '5'
end
but for one-liners it is a must. So what you need is either:
if 5 == 5 then puts '5' end
or even shorter switching "then" for ":"
if 5 == 5 : puts '5' end