Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Enumerable methods returning Enumerable (was: ruby-dev suumary 26862-26956)

Reply
Thread Tools

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

 
 
Daniel Sheppard
Guest
Posts: n/a
 
      09-16-2005
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: http://www.velocityreviews.com/forums/(E-Mail Removed) [(E-Mail Removed)]=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.
################################################## #######################=
############


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
String#each_*slice* methods (like Enumerable#each_slice) Aaron D. Gifford Ruby 4 04-06-2011 11:33 PM
Is there a way to find the class methods of a class, just like'methods' finds the instance methods? Kenneth McDonald Ruby 5 09-26-2008 03:09 PM
returning none when it should be returning a list? randomtalk@gmail.com Python 11 05-02-2006 10:26 AM
ruby-dev suumary 26957-27102 SASADA Koichi Ruby 3 09-21-2005 03:10 PM
ruby-dev suumary 26862-26956 Masayoshi Takahashi Ruby 3 09-15-2005 09:52 PM



Advertisments