Conditional structures/Ruby: Difference between revisions

m
 
Line 9:
deus_ex
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===
Anonymous user