Ruby Array of Symbols Shorthand

I am a big fan of Ruby shorthand and I use them every time I get the opportunity. I just ran across one that I have never used before. This syntax allows you to create an array of symbols.

%i(array of symbols shall follow)
 => [:array, :of, :symbols, :shall, :follow] 

I have to admit it is nothing mind blowing, but none the less useful. It will allow you to do things like define a list of symbols and itterate over them pretty seemlessly.

%i(array of symbols shall follow).each{|s| puts s}
array
of
symbols
shall
follow
 => [:array, :of, :symbols, :shall, :follow] 

Categories

ruby
shorthand

Comments