C
Corey Haines
I need to add a string to the end of an array count number of times. I
was wondering if I could get some advice on the prefered way to do it
in Ruby.
@bucket is the array
def add_person(count, name)
@bucket += Array.new(count, name)
end
or some other ideas
def add_person(count, name)
count.times {@bucket << name }
end
# or some variation of looping
Personally, I like the adding a new array to the @bucket array. I
realize (at least I assume) that it creates a temporary Array, but I
think it is more understandable?
Thoughts?
Thanks, I'm just learning Ruby
-Corey
was wondering if I could get some advice on the prefered way to do it
in Ruby.
@bucket is the array
def add_person(count, name)
@bucket += Array.new(count, name)
end
or some other ideas
def add_person(count, name)
count.times {@bucket << name }
end
# or some variation of looping
Personally, I like the adding a new array to the @bucket array. I
realize (at least I assume) that it creates a temporary Array, but I
think it is more understandable?
Thoughts?
Thanks, I'm just learning Ruby
-Corey