Can I add object to an array in a loop and then return the array in the same line?

  • A+

I have some simple ruby code where I create an Array, create a bunch of objects and push them into the array and then return the array

def create_barcodes(count)   barcodes =   count.times { barcodes.push(Barcode.create) }   barcodes end 

It feels like there should be a way to reduce this to one or two lines and at a minimum avoid having to reference the barcodes array at the end so it gets returned. Is there some clever way to get the count loop to return the array?

barcodes ={ Barcode.create } 


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: