Array method
Ruby's Array(arg)
method, from the Kernel class, is awesome. I like it because to me it's really clear what it does (type casting), and it tries both to_ary
and to_a
.
Also, it just looks cool.
2.1.0 :001 > Array(%w(some cool words))
=> ["some", "cool", "words"]
2.1.0 :002 > Array("word")
=> ["word"]
2.1.0 :003 > Array(nil)
=> []
2.1.0 :004 > Array(1..5)
=> [1, 2, 3, 4, 5]
Tweet