Conditional structures/Ruby: Difference between revisions

Content added Content deleted
 
Line 9: Line 9:
deus_ex
deus_ex
end</lang>
end</lang>

Note that <code>if...end</code> is an expression, so its return value can be captured in a variable:

<lang ruby>
s = 'yawn'
result = if s == 'Hello World'
:foo
elsif s == 'Bye World'
:bar
else
:deus_ex
end
# result now holds the symbol :deus_ex</lang>


===ternary===
===ternary===