Hi,
In message "[ruby-talk:02376] Iterator into array"
on 00/04/07, Dave Thomas <Dave / thomases.com> writes:
|Dave's stupid question of the week:
|
|Given an iterator method, how can I get the results expressed as an
|array? I could do:
|
| result = []
| iteratorMethod { |i| result << i }
|
|But this seems ugly - there must be a more functional way of doing this. Any
|ideas?
I think it may be uglier, but for the idea:
def iterated_values(method, *args)
result = []
method.call(*args) do |x|
result.push(x)
end
result
end
p iterated_values([1,2].method(:each))
matz.