Array#select doesnt return Enumerator?

View: New views
3 Messages — Rating Filter:   Alert me  

Array#select doesnt return Enumerator?

by kang-sze lin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
    I have tried jruby1.4, and something works in ruby1.8.7 doesn't works in jruby1.4.
My code is like below.

array = ['a','b','c']
array.select.with_index{|x, i| i >= 1}

got C:/Program Files/jruby-1.4.0/lib/ruby/site_ruby/shared/builtin/core_ext/symbol.rb:1:in `select': yield called out of block (LocalJumpError)

but this works well

array = ['a','b','c']
q = array.enum_for(:select).with_index{|x, i| i >= 1}

  Is this a bug? and Should i file it in jira?

  koji

Re: Array#select doesnt return Enumerator?

by Hirotsugu Asari :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Nov 4, 2009, at 9:40 PM, koji Lin wrote:

Hi,
    I have tried jruby1.4, and something works in ruby1.8.7 doesn't works in jruby1.4.
My code is like below.

array = ['a','b','c']
array.select.with_index{|x, i| i >= 1}

got C:/Program Files/jruby-1.4.0/lib/ruby/site_ruby/shared/builtin/core_ext/symbol.rb:1:in `select': yield called out of block (LocalJumpError)

but this works well

array = ['a','b','c']
q = array.enum_for(:select).with_index{|x, i| i >= 1}

  Is this a bug? and Should i file it in jira?

  koji

It looks like a bug to me, in the sense that JRuby's behavior deviates from MRI's. The thing is, Enumerable#select without body doesn't seem to be documented (please educate me if I missed the documentation), so in that sense, it is not. In fact, there are no spec on Array#select that contains no blocks (yet).

Regardless, I think it is worth opening a JIRA ticket.

By the way, the code works with JRuby in 1.9 mode.

Hiro



Re: Array#select doesnt return Enumerator?

by David Calavera :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In the last ruby build there were some backports that haven't been included in jruby yet, perhaps that's one of those. I'm filing a bug and sending a patch in a while.

On Thu, Nov 5, 2009 at 6:31 AM, Hirotsugu Asari <asari.ruby@...> wrote:

On Nov 4, 2009, at 9:40 PM, koji Lin wrote:

Hi,
    I have tried jruby1.4, and something works in ruby1.8.7 doesn't works in jruby1.4.
My code is like below.

array = ['a','b','c']
array.select.with_index{|x, i| i >= 1}

got C:/Program Files/jruby-1.4.0/lib/ruby/site_ruby/shared/builtin/core_ext/symbol.rb:1:in `select': yield called out of block (LocalJumpError)

but this works well

array = ['a','b','c']
q = array.enum_for(:select).with_index{|x, i| i >= 1}

  Is this a bug? and Should i file it in jira?

  koji

It looks like a bug to me, in the sense that JRuby's behavior deviates from MRI's. The thing is, Enumerable#select without body doesn't seem to be documented (please educate me if I missed the documentation), so in that sense, it is not. In fact, there are no spec on Array#select that contains no blocks (yet).

Regardless, I think it is worth opening a JIRA ticket.

By the way, the code works with JRuby in 1.9 mode.

Hiro





--
David Calavera
http://www.thinkincode.net