4 ms·
Ah, that's interesting – they become expression modifiers instead. x = (:false if true) => :false x = (:false if false) => nil Any other if stateme
by matthewmacleod 11y ago
Ah, that's interesting – they become expression modifiers instead.
x = (:false if true)
=> :false
x = (:false if false)
=> nil
Any other if statement does appear to be treated as a value:
x = if true then 5 else 10 end
=> 5
- kbenson 11y agoAnd that's different than in Perl, where they aren't statement modifiers (I slightly misspoke), they really are just rearranged into single statement if blocks. That is, if the postconditional is false, the statement is not executed at all. my $x = 1; $x = 10 if $x > 1; say $x; # 1 Personally I find the assignment of the if/else statement's return value distasteful, as it's both complex to read and mixes a portion of a natural pattern of thinking while later abandoning it, making it unintuitive. At that level, I prefer a ternary operator.