Skip to content

Instantly share code, notes, and snippets.

@tanelsuurhans
Created May 22, 2015 17:05
Show Gist options
  • Save tanelsuurhans/5d946454822d2544edbb to your computer and use it in GitHub Desktop.
Save tanelsuurhans/5d946454822d2544edbb to your computer and use it in GitHub Desktop.
# 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
Copy link

jwirman commented May 22, 2015

case variable
when "value1" then do_stuff
when "value2" then do_stuff
end

@ckmorris
Copy link

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 :)

@zachallett
Copy link

Not digging @jwirman's. One would expect that to be a hanging guard clause vs the do_stuff action

@JulioGMedina
Copy link

My personal pref is #1. Makes the scope very visibly clear.

@rthbound
Copy link

#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

@jwirman
Copy link

jwirman commented May 26, 2015

officially voting for option #2 now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment