Project

General

Profile

Actions

Bug #2702

closed

Enumerator#to_a and #to_set yield inconsistent results

Added by sylvain.joyeux (Sylvain Joyeux) about 14 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
ruby -v:
ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux]
[ruby-core:27985]

Description

=begin
If I run #to_a and #to_set on an Enumerator with a multiple-argument yield, then I get the following:

[~]% cat test_to_set.rb
require 'set'

def enumerate
yield(1, 2, 3)
yield(4, 5, 6)
end

STDERR.puts enum_for(:enumerate).class
STDERR.puts enum_for(:enumerate).to_a.inspect
STDERR.puts enum_for(:enumerate).to_set.inspect

[~]% ruby1.9.1 test_to_set.rb
Enumerator
[[1, 2, 3], [4, 5, 6]]
#<Set: {1, 4}>

Namely, #to_a captures all the arguments provided to yield() while #to_set only gets the first one.

I guess that the #to_set behaviour is a bug (isn't it ?)
=end

Actions #1

Updated by hylian (Roberto Perez) almost 14 years ago

=begin
I have tested it in the version built today using OSX:

ruby 1.9.2dev (2010-05-04 trunk 27603) [x86_64-darwin10.3.0]

and the test was different to that, and I suposse that this:

$ ./ruby -I /Users/roberto/Projects/Ruby/ruby-core/ruby/lib /tmp/to_set.rb
Enumerator
[[1, 2, 3], [4, 5, 6]]
#<Set: {[1, 2, 3], [4, 5, 6]}>

Is now OK.

Cheers.

=end

Actions #2

Updated by marcandre (Marc-Andre Lafortune) almost 14 years ago

  • Status changed from Open to Closed

=begin

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0