Last active
January 2, 2018 13:07
-
-
Save rachidcalazans/c4021e446077d222e4b01bf0ed38fbb0 to your computer and use it in GitHub Desktop.
Example III Refactored 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) | |
state_action = { | |
in_progress: :save_in_progress, | |
done: :save_done, | |
on_review: :save_on_review | |
} | |
action = state_action[state] | |
self.send(action, params) | |
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