Created
May 22, 2015 17:05
-
-
Save tanelsuurhans/5d946454822d2544edbb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# option one | |
case variable | |
when "value1" | |
do_stuff | |
when "value2" | |
do_stuff | |
else | |
do_stuff | |
end | |
# option 2 | |
case variable | |
when "value1" | |
do_stuff | |
when "value2" | |
do_stuff | |
else | |
do_stuff | |
end |
jwirman
commented
May 22, 2015
I like no indents on case statements, but I hadn't seen the when / then pair Justin presented. +1 for Justin's solution +1 for Option 2 :)
Not digging @jwirman's. One would expect that to be a hanging guard clause vs the do_stuff
action
My personal pref is #1. Makes the scope very visibly clear.
#2 is my choice. begin/rescue/end stuff is indented similarly:
begin
do_stuff
rescue
whoops_stuff
end
def some_method
do_stuff
rescue
whoops_stuff
end
To me, option #1 looks as silly as:
if condition
do_stuff
else
do_other_stuff
end
officially voting for option #2 now :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment