Organize my array ruby -
im trying optimize code as possible , i've reached dead end.
my code looks this:
class person attr_accessor :age def initialize(age) @age = age end end people = [person.new(10), person.new(20), person.new(30)] newperson1 = [person.new(10)] newperson2 = [person.new(20)] newperson3 = [person.new(30)] is there way can ruby automatically pull data out people array , name them following newperson1 , on..
best regards
that code smell. should refer them [people[0]], [people[1]], ... .
but if insist on doing so, , if can wait until december 25 (ruby 2.1), can do:
people.each.with_index(1) |person, i| binding.local_variable_set("newperson#{i}", [person]) end
Comments
Post a Comment