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

Discussion in 'Ruby' started by Daniel Sheppard, Sep 16, 2005.

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

    require 'enumerator'

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

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

    -----Original Message-----
    From: [mailto:]=20
    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=20
    > > Enumerable method is called without block. It's applied to each or=20
    > > each-like methods in Array, Dir, Hash, IO, Range, String and Struct.
    > >=20
    > > http://www.rubyist.net/~nobu/ruby/enumerator.diff

    >=20
    > Um. Any chance of seeing this in Ruby 1.8.x? I'm supposing this is=20
    > 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.
    #########################################################################=
    ############
     
    Daniel Sheppard, Sep 16, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ron Peterson

    /dev/urandom vs. /dev/random

    Ron Peterson, Jan 7, 2005, in forum: C Programming
    Replies:
    21
    Views:
    1,542
    Keith Thompson
    Jan 13, 2005
  2. Masayoshi Takahashi

    ruby-dev suumary 26862-26956

    Masayoshi Takahashi, Sep 15, 2005, in forum: Ruby
    Replies:
    3
    Views:
    115
  3. SASADA Koichi

    ruby-dev suumary 26957-27102

    SASADA Koichi, Sep 21, 2005, in forum: Ruby
    Replies:
    3
    Views:
    119
  4. Kenneth McDonald
    Replies:
    5
    Views:
    324
    Kenneth McDonald
    Sep 26, 2008
  5. Aaron D. Gifford
    Replies:
    4
    Views:
    145
    7stud --
    Apr 7, 2011
Loading...

Share This Page