title: Array() applied to hashes?
body: <p>Recently I stumbled upon "<a href="http://batsov.com/articles/2013/06/28/the-elements-of-style-in-ruby-number-3-make-sure-something-is-an-array/" rel="nofollow">The Elements of Style in Ruby #3: Make Sure Something Is an Array</a>".</p>
  
  <p>TL;DR: The Method <code>Array()</code> in Ruby converts anything you put in, into an array and tries to guess what the correct outcome should be:</p>
  
  <pre><code>Array(1)     # =&gt; [1]
  Array([1,2]) # =&gt; [1,2]
  Array(nil)   # =&gt; []
  </code></pre>
  
  <p>So what does <code>Array({a: :b})</code> return? I would assume it returns an array with the hash as a value: <code>[{a: :b}]</code>.</p>
  
  <p>However, the hash is converted directly into an array: <code>[:a, :b]</code>.</p>
  
  <p>I don't just want to put a hash into an array (<code>[{a: :b}]</code>). I'd like to have functionality that returns an array no matter what I put in. <code>Array()</code> already does that, but it converts a hash to an array in a way that I don't expect.</p>
  
  <p>So, basically the functionality should look like this:</p>
  
  <pre><code>NewFancyArrayMethod({a: :b}) # =&gt; [{a: :b}]
  NewFancyArrayMethod([{a: :b}, {c: :d}]) # =&gt; [{a: :b}, {c: :d}]
  </code></pre>
  
  <p>The second part is already fulfilled by <code>Array()</code>.</p>
  
  <p>I know I can do something like <code>values = [values] unless values.is_a? Array</code>, like the article points out. However, I would rather have a method that abstracts this conversion from me as <code>Array()</code> already does. The only problem is that <code>Array()</code> treats a hash differently than any other "single" value (String, Integer, Object, etc.). I simply don't want different handling for different cases.</p>