Create or append to array in Ruby

foo ||= []
foo << :element

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


(foo ||= []) << :element

But meh. Is it really so onerous to keep it readable?


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

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