Why does 6.times.map work in ruby 1.8.7 but not 1.8.6

Posted by Lee on Stack Overflow See other posts from Stack Overflow or by Lee
Published on 2010-05-02T21:18:36Z Indexed on 2010/05/02 21:28 UTC
Read the original article Hit count: 421

The following code snippet works fine in 1.8.7 on Mac OS X, but not in 1.8.6 on Ubuntu. Why? Is there a workaround?

Works in 1.8.7:

$ ruby --version
ruby 1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0]
ltredgate15:eegl leem$ irb
>> 6.times.map {'foo'}
=> ["foo", "foo", "foo", "foo", "foo", "foo"]
>>

But not in 1.8.6:

# ruby --version
ruby 1.8.6 (2008-08-11 patchlevel 287) [i686-linux]
Ruby Enterprise Edition 20090610
# irb
irb(main):001:0> 6.times.map {'foo'}
LocalJumpError: no block given
        from (irb):1:in `times'
        from (irb):1
irb(main):002:0> 

Why is there a difference? What's the workaround for 1.8.6?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-enterprise-edition