Last active
January 2, 2018 13:07
-
-
Save rachidcalazans/0980b3dc23af240db02a3058c3ce164d to your computer and use it in GitHub Desktop.
Example III for the Post - avoiding-conditionals
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
def save(state, params) | |
if state == :in_progress | |
return save_in_progress(params) | |
elsif state == :done | |
return save_done(params) | |
elsif state == :on_review | |
return save_on_review(params) | |
end | |
end | |
def save_in_progress(params) | |
puts 'called save_in_progress' | |
end | |
def save_done(params) | |
puts 'called save_done' | |
end | |
def save_on_review(params) | |
puts 'called save_on_review' | |
end | |
params = { a: 1, b: 2, c: 3 } | |
save(:in_progress, params) #=> "called save_in_progress" | |
save(:done, params) #=> "called save_done" | |
save(:on_review, params) #=> "called save_on_review" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment