Percent Notation and Symbols in Ruby 2.0


Ruby is nice because it has the percent notation for working with different base elements such as strings, arrays, and symbols. You can create different objects by replacing the character after the '%' mark.

    >> %q{Foo Bar}
    => "Foo Bar"
    >>
    >> %w{Foo Bar}
    => ["Foo", "Bar"]
    >>
    >> %s{Foo Bar}
    => :"Foo Bar"

With the arrival of ruby 2.0, you can generate an array of symbols as such:

    >> %i{Foo Bar}
    => [:Foo, :Bar]

It is encouraged to use symbols in your code because it saves time and memory, and this new feature makes it easier to implement.