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

Enumerable#each_entry behaves differently from MRI #3738

Closed
toy opened this issue Mar 18, 2017 · 1 comment
Closed

Enumerable#each_entry behaves differently from MRI #3738

toy opened this issue Mar 18, 2017 · 1 comment

Comments

@toy
Copy link

toy commented Mar 18, 2017

Enumerable#each_entry yields different from MRI value for no arguments.

Ran using docker image, ruby -v:
rubinius 3.72 (2.3.1 6d56979 2017-02-21 3.8.0) [x86_64-linux-gnu]

test file:

class Foo
  include Enumerable

  def each
    yield 1
    yield 1, 2
    yield
  end
end

out = []
Foo.new.each_entry{ |*args| out << args }
puts "each_entry: #{out.inspect}"

Expected output:

==[1.9.3-p551]==
each_entry: [[1], [[1, 2]], [nil]]

==[2.0.0-p648]==
each_entry: [[1], [[1, 2]], [nil]]

==[2.1.10]==
each_entry: [[1], [[1, 2]], [nil]]

==[2.2.6]==
each_entry: [[1], [[1, 2]], [nil]]

==[2.3.3]==
each_entry: [[1], [[1, 2]], [nil]]

==[2.4.0]==
each_entry: [[1], [[1, 2]], [nil]]

Rubinius output:

each_entry: [[1], [[1, 2]], [[]]]

I suggest following change:

diff --git core/enumerable.rb core/enumerable.rb
index 2234f9b61d..a35e2eb1ff 100644
--- core/enumerable.rb
+++ core/enumerable.rb
@@ -67,8 +67,8 @@ module Enumerable

   def each_entry(*pass)
     return to_enum(:each_entry, *pass) { enumerator_size } unless block_given?
-    each(*pass) do |*element|
-      yield element.size == 1 ? element[0] : element
+    each(*pass) do |*elements|
+      yield elements.size > 1 ? elements : elements[0]
     end
     self
   end

Related: jruby/jruby#4532

@kachick
Copy link
Member

kachick commented Nov 4, 2017

@toy Thanks for your reporting! Sorry to late response 🙇 We fixed the problem in #3761.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants