Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#to_ary behavior does not conform to MRI Ruby (1.7.22) #3378

asthasr opened this issue Oct 8, 2015 · 1 comment

#to_ary behavior does not conform to MRI Ruby (1.7.22) #3378

asthasr opened this issue Oct 8, 2015 · 1 comment


Copy link

asthasr commented Oct 8, 2015

In MRI Ruby, when you iterate over an object providing a block with extra parameters, it seems that #to_ary is called and, if it returns nil, is disregarded. This is a test that you can execute to see the behavior on different Rubies:

class Example
  def to_ary

test = [].map { |x, _| x }

puts test == [nil] ? "fail" : "pass"

On MRI versions, this passes. On JRuby 1.7.22, it returns [nil] and thus fails. On JRuby, it raises an exception: TypeError: Example#to_ary should return Array. It seems that the behavior in this case should conform to the behavior on MRI, in order to avoid surprising behavior when attempting to use map, each and other enumerable methods.

In real projects, this is observable on any ActiveRecord object as well as DelayedJob, as seen in Issue #3338.

Note -- I am opening this bug for 1.7.22 per a request from @enebo .

Copy link

enebo commented Oct 8, 2015

commit noted for this in #3338.

@enebo enebo closed this as completed Oct 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

2 participants