Like others, I'm confused about the example (array
is not defined, and this_method
is never called). But you certainly don't need the while loop. I'd just use the Integer#times
method, since you're making no use of the array values:
array.length.times {|i| yield week[i]}
#each_index
(which ram suggested) works just as well.
But if array
is actually meant to be week
, then it gets even simpler:
week.each {|x| yield x}
I'm not sure why you'd want to create a method that just recycles #each
though.