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

D

Daniel Sheppard

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: (e-mail address removed) [mailto:[email protected]]=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.
#########################################################################=
############
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top