Created
April 6, 2012 04:13
-
-
Save cadwallion/2316780 to your computer and use it in GitHub Desktop.
My solution to Array() shenanigans
This file contains hidden or 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
class Array | |
def self.i_want_a_goddamn_array thing | |
if thing.kind_of? Hash | |
[thing] | |
else | |
Array(thing) | |
end | |
end | |
end |
This file contains hidden or 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
>> 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