title: Variable assignment using hash vs if statements
body: <p>Lately when coding in Ruby, when I need a variable assigned differently depending on some input to a method, I've been using a Hash like this:</p>
  
  <pre><code>variable = { "option1" =&gt; [1,2,3], "option2" =&gt; [3,2,1]}[input]
  </code></pre>
  
  <p>The thing I like most about this approach is the scalability: the input can be one of, say, five different values, which with <code>if</code> statements would be a bit messy.</p>
  
  <p>But what am I losing when doing this? Larger memory use as the Hash needs to be initialized? Slower? Faster?</p>
  
  <p>For comparison, an equivalent <code>if</code> statement could be:</p>
  
  <pre><code>variable = Array.new
  if input.eql?("option1")
    variable = [1,2,3]
  else
    variable = [3,2,1]
  end
  </code></pre>
  
  <p>(Yes, I could have used <code>?</code> notation for two options, but not for more, so I wanted to show the structure in comparison.)</p>