amindfv amindfv - 1 month ago 14
Ruby Question

Create or append to array in Ruby

foo ||= []
foo << :element


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

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

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