Last active
January 2, 2018 13:06
-
-
Save rachidcalazans/f9be2e19e4b2ec14e41bdd25c8af9245 to your computer and use it in GitHub Desktop.
Example II 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 extract_params(state, params) | |
if state == :in_progress | |
return params.select { |k, v| [:key_a, :key_b].include?(k) } | |
elsif state == :done | |
return params.select { |k, v| [:key_c, :key_d].include?(k) } | |
elsif state == :on_review | |
return params.select { |k, v| [:key_e, :key_f].include?(k) } | |
end | |
end | |
params = { key_a: 1, key_b: 2, key_c: 3, key_d: 4, key_e: 5, key_f: 6 } | |
extract_params(:in_progress, params) #=> { key_a: 1, key_b: 2 } | |
extract_params(:done, params) #=> { key_c: 3, key_d: 4 } | |
extract_params(:on_review, params) #=> { key_e: 5, key_f: 6 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment