Tuesday, July 31, 2012

Create array using %w



Use %w as a shortcut to make an array. For example...

a = %w{ ant bee cat dog elk } will give you...

a = [ 'ant', 'bee', 'cat', 'dog', 'elk' ]

To test (inside irb),
a[0]
=> "ant"

a[3]
=> "dog"

Source - Programming Ruby

No comments:

Post a Comment