Skip to content

Instantly share code, notes, and snippets.

@cadwallion
Created April 6, 2012 04:13
Show Gist options
  • Save cadwallion/2316780 to your computer and use it in GitHub Desktop.
Save cadwallion/2316780 to your computer and use it in GitHub Desktop.
My solution to Array() shenanigans
class Array
def self.i_want_a_goddamn_array thing
if thing.kind_of? Hash
[thing]
else
Array(thing)
end
end
end
>> Array.i_want_a_goddamn_array []
=> []
>> Array.i_want_a_goddamn_array nil
=> []
>> Array.i_want_a_goddamn_array({foo: 'bar'})
=> [{:foo=>"bar"}]
>> Array.i_want_a_goddamn_array [{foo: 'bar'}, {bar: 'baz'}]
=> [{:foo=>"bar"}, {:bar=>"baz"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment