On Jan 11, 2008, at 7:13 PM, Roger Pack wrote:

>   12.times do |month_ahead|
>   end
>
> returns 12
> I would have expected this to return a collected array of the return
> value of each block.  Odd?

To get a collected array:

 >> (0...12).collect { |x| x * 2 }
=> [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]

Or via enumerators in Ruby 1.8:

 >> require 'enumerator'
=> true
 >> 12.enum_for(:times).collect { |x| x * 2 }
=> [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]


Or via Ruby 1.9's new enumerator behavior:

 >> 12.times.collect { |x| x * 2 }
=> [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]


Gary Wright