remove - ruby uniq




Create or append to array in Ruby (2)

You also could benefit from the Kernel#Array, like:

# foo = nil
foo = Array(foo).push(:element)
# => [:element]

which has the benefit of flattening a potential Array, like:

# foo = [1]
foo = Array(foo).push(:element)
# => [1, :element]
foo ||= []
foo << :element

Feels a little clunky. Is there a more idiomatic way?


You can always use the push method on any array too. I like it better.

(a ||= []).push(:element)




arrays