4 ms·
Well, you could do something like this in Ruby: def my_if_else( cond, a, b ) if cond a.call else b.call end end x = 2 my_if_els
by wedesoft 17y ago
Well, you could do something like this in Ruby:
def my_if_else( cond, a, b )
if cond
a.call
else
b.call
end
end
x = 2
my_if_else x < 0, proc { "#{x} is lower than zero" },
proc { "#{x} is greater or equal zero" }
My point is that you can't do without 'proc' (or 'sub' in your case).
- draegtun 17y agoOpps, my last comment/code got cut off :( Here goes again.... And going into sub prototype sublime you can also do: sub then (&@) { @_ } sub elsedo (&@) { @_ } my $x = 2; my_if_else $x < 0, then { say "$x is lower than zero" } elsedo { say "$x is greater or equal to zero" }; But yes, I do get your point about proc/sub. There is only so far you could (and should!) stretch the parsers syntax. There is always macros (see Devel::Declare in Perl) if you're mad enough to want cosmetic purity :)