Today I Learned

hashrocket A Hashrocket project

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]
See More #ruby TILs
Looking for help? Each developer at Hashrocket has years of experience working with Ruby applications of all types and sizes. We're an active presence at Ruby conferences, have written some of the most popular gems, and have worked on many of the web's Ruby on Rails success stories. Contact us today to talk about your Ruby project.