Enumerable methods returning Enumerable (was: ruby-dev suumary 26862-26956)

Hmmm... I probably shouldn't have included String#scan in that, as scan
already has non-block behaviour (it returns an array).

···

-----Original Message-----
From: Daniel Sheppard
Sent: Friday, 16 September 2005 12:41 PM
To: ruby-talk ML
Subject: Enumerable methods returning Enumerable (was: ruby-dev suumary
26862-26956)

If I'm understanding the change properly, the following code should do
the same thing:

require 'enumerator'

{
  Array => [:each, :each_index, :reverse_each],
  Dir => [:each],
  Hash => [:each],
  IO => [:each, :each_byte, :each_line],
  Range => [:each],
  String => [:each, :each_byte, :each_line, :scan],
  Struct => [:each],
}.each { |c, ms|
  ms.each { |m|
    c.class_eval(<<-EOF)
      alias :__fix_enumerable_#{m} :#{m}
      private :__fix_enumerable_#{m}
      def #{m} (*args, &block)
        if block
          __fix_enumerable_#{m}(*args,
&block)
        else
          enum_for(:__fix_enumerable_#{m},
*args)
        end
      end
    EOF
  }
}

p "abcdefg".each_byte.collect { |x| (x+1).chr }.join => "bcdefgh"

-----Original Message-----
From: nobu.nokada@softhome.net [mailto:nobu.nokada@softhome.net]
Sent: Friday, 16 September 2005 7:53 AM
To: ruby-talk ML
Subject: Re: ruby-dev suumary 26862-26956

Hi,

At Fri, 16 Sep 2005 02:38:30 +0900,
Austin Ziegler wrote in [ruby-talk:156292]:

> [ruby-dev:26924] enumerator
> Nobuyoshi Nakada made a patch to return Enumerator object when
> Enumerable method is called without block. It's applied to each or
> each-like methods in Array, Dir, Hash, IO, Range, String and Struct.
>
> http://www.rubyist.net/~nobu/ruby/enumerator.diff

Um. Any chance of seeing this in Ruby 1.8.x? I'm supposing this is
instead of a LocalJumpError.

It would be radical change for stable version, at least 1.8.3.

--
Nobu Nakada

########################################################################
#############
This email has been scanned by MailMarshal, an email content filter.
########################################################################
#############

#####################################################################################
This email has been scanned by MailMarshal, an email content filter.
#####################################################################################