I know there is a shorthand one-line if/else statement in Ruby:
a ? b : c
Is there one for just a single if statement? Instead of writing this:
if
if a # do something end
Is there a shorthand version of this?
You can use post conditions (don't mind the name, it will be evaluated before the code. And do_something will only be executed if condition evaluates to truthy value (i.e. not nil or false)).
do_something
nil
false
do_something if a
1.4m articles
1.4m replys
5 comments
57.0k users