Last Updated: February 25, 2016
·
756
· jmarizgit

Ruby easy arrays

A simple declaration of an array in Ruby for my name ( I'm assuming you are using irb console):

$ name = ["jose", "mariz", "melo", "formiga", "viana"]
=> ["jose", "mariz", "melo", "formiga", "viana"]

That works fine but is a little exhausting, don't you think? Ruby language provide you an easier way to do this, using '%w[]', let's try that:

$ name = %w[jose mariz melo formiga viana]
=> ["jose", "mariz", "melo", "formiga", "viana"]

Happy Hacking!