Ruby Language Create Array of Symbols


Example

2.0
array = %i(one two three four)

Creates the array [:one, :two, :three, :four].

Instead of %i(...), you may use %i{...} or %i[...] or %i!...!

Additionally, if you want to use interpolation, you can do this with %I.

2.0
a = 'hello'
b = 'goodbye'
array_one = %I(#{a} #{b} world)
array_two = %i(#{a} #{b} world)

Creates the arrays: array_one = [:hello, :goodbye, :world] and array_two = [:"\#{a}", :"\#{b}", :world]