3 ms·
Be careful with Array() since it uses #to_a method whenever it exists. As such, this trick is unsuitable for array of hashes (in any version of ruby) and string
by xentronium 13y ago
Be careful with Array() since it uses #to_a method whenever it exists. As such, this trick is unsuitable for array of hashes (in any version of ruby) and strings (in ruby 1.8).
Other Enumerables might make for unpleasant surprise too.
Old mootools had $A method (called Array.from now) which did exactly what you expected.
- byroot 13y agoIf you already use ActiveSupport, then you can use Array#wrap http://api.rubyonrails.org/classes/Array.html#method-c-wrap http://api.rubyonrails.org/classes/Array.html#method-c-wrap
- xentronium 13y agoThis is exactly what I meant! Thank you!