Refactoring conditional variable assignment
refactoring, ruby
Solution
Just put the assignment outside the if.
x = if some condition
some value
elsif another condition
a different value
Or you could use a Hash.
x = dict[some condition]
Problem
I'm working on a project. Currently I have a fairly large conditional statement, that assigns a value to a variable based on some input parameters. So, I have something like this. ``` if some condition x = some value elsif another condition x = a different value ... ``` What's the best way to refactor this? I'm hoping that I might end up with something like ``` x = some value if some condition || another value if another condition ``` Is there a pattern for this sort of thing?