[#147004] How and where Fixnum are created — "Eustaquio Rangel de Oliveira Jr." <eustaquiorangel@...>

-----BEGIN PGP SIGNED MESSAGE-----

10 messages 2005/07/01

[#147009] no clue — Joe Van Dyk <joevandyk@...>

I thought for all of five seconds for a good subject line for this

36 messages 2005/07/01
[#147028] Re: no clue — Daniel Brockman <daniel@...> 2005/07/02

Joe Van Dyk <joevandyk@gmail.com> writes:

[#151840] Re: no clue — Joe Van Dyk <joevandyk@...> 2005/08/12

On 7/1/05, Daniel Brockman <daniel@brockman.se> wrote:

[#151998] Re: no clue — Simon Krer <SimonKroeger@...> 2005/08/12

[#152051] Re: no clue — Simon Krer <SimonKroeger@...> 2005/08/13

Hi Joe,

[#152078] Re: no clue — Joe Van Dyk <joevandyk@...> 2005/08/13

On 8/13/05, Simon Krer <SimonKroeger@gmx.de> wrote:

[#152089] Re: no clue — Simon Krer <SimonKroeger@...> 2005/08/13

[#152093] Re: no clue — Joe Van Dyk <joevandyk@...> 2005/08/14

On 8/13/05, Simon Krer <SimonKroeger@gmx.de> wrote:

[#147044] Loading a file without cluttering the global namespace — Benjamin Hepp <benjamin-hepp@...>

Hello,

11 messages 2005/07/02

[#147056] class variable leading a double life — "Amarison" <amarison@...>

Can someone please explain why the @var variable leads a double life? One

20 messages 2005/07/02

[#147153] Ruby under Cygwin problems — JZ <usenet@...>

Whatever Ruby module I want to install under Cygwin I always get the same

30 messages 2005/07/04
[#147236] Re: Ruby under Cygwin problems — "karlin.fox@..." <karlin.fox@...> 2005/07/05

> No this is not the problem, it's just one more of this quick and dirty hacks (that i don't like in ruby).

[#147239] Re: Ruby under Cygwin problems — "Ryan Leavengood" <mrcode@...> 2005/07/05

karlin.fox@gmail.com said:

[#147280] Extract/Parse String? — tuyet.ctn@...

How do I extract "treeframe1120266500902" from this String class

12 messages 2005/07/06

[#147300] Inheriting Array and slice() behaviour — Sylvain Joyeux <sylvain.joyeux@...>

I have a class inheriting Array, and I expected slice() and []

43 messages 2005/07/06
[#147327] Re: Inheriting Array and slice() behaviour — Yukihiro Matsumoto <matz@...> 2005/07/06

Hi,

[#147348] Re: Inheriting Array and slice() behaviour — "Robert Klemme" <bob.news@...> 2005/07/06

William Morgan <wmorgan-ruby-talk@masanjin.net> wrote:

[#147437] Re: Inheriting Array and slice() behaviour — William Morgan <wmorgan-ruby-talk@...> 2005/07/07

Excerpts from Robert Klemme's mail of 6 Jul 2005 (EDT):

[#147443] Re: Inheriting Array and slice() behaviour — "Ara.T.Howard" <Ara.T.Howard@...> 2005/07/07

On Fri, 8 Jul 2005, William Morgan wrote:

[#147465] Re: Inheriting Array and slice() behaviour — William Morgan <wmorgan-ruby-talk@...> 2005/07/07

Excerpts from Ara.T.Howard's mail of 7 Jul 2005 (EDT):

[#147483] Re: Inheriting Array and slice() behaviour — Pit Capitain <pit@...> 2005/07/07

William Morgan schrieb:

[#147355] Major web host supports Rails — bertrandmuscle@...

One of the biggest web hosts on the internet (Dreamhost) now supports

32 messages 2005/07/06
[#147761] Re: Major web host supports Rails — Dennis Roberts <denrober@...> 2005/07/11

Want to support Ruby? Use Textdrive (http://www.textdrive.com/).

[#147421] Ruby as mathematical language — "none" <webb.sprague@...>

Hi Ruby world.

27 messages 2005/07/07

[#147504] ruby-1.8.2: test.rb: Seg Fault in test_check "exception" — me2faster@...

I reduced the sample/test.rb to just the test_check "exception"

12 messages 2005/07/07

[#147506] Ruby in XML. — John Carter <john.carter@...>

I have just stuck this on..

16 messages 2005/07/08

[#147542] Re: accessing index inside map — "Pe, Botp" <botp@...>

nobuyoshi nakada [mailto:nobuyoshi.nakada@ge.com] wrote:

26 messages 2005/07/08
[#147548] Re: accessing index inside map — "Robert Klemme" <bob.news@...> 2005/07/08

Pe, Botp wrote:

[#147651] Strings vs arrays — Luke Worth <luke@...>

Hi.

25 messages 2005/07/09
[#147670] Re: Strings vs arrays — Daniel Brockman <daniel@...> 2005/07/09

Luke Worth <luke@worth.id.au> writes:

[#147711] Programming the Lego robots using Ruby technology. — Victor Reyes <victor.reyes@...>

Do anyone knows if there is a Ruby API to program the Lego robots?

8 messages 2005/07/10
[#147712] Re: Programming the Lego robots using Ruby technology. — "daz" <dooby@...10.karoo.co.uk> 2005/07/11

[#147720] Re: accessing index inside map — "Pe, Botp" <botp@...>

Yukihiro Matsumoto [mailto:matz@ruby-lang.org] wrote:

28 messages 2005/07/11
[#147722] Re: accessing index inside map — Yukihiro Matsumoto <matz@...> 2005/07/11

Hi,

[#147790] class_attr_accessor — "Jeffrey Moss" <jeff@...>

I was playing around with class variables and class instance variables

16 messages 2005/07/11

[#147895] Updating GUIs — Joe Van Dyk <joevandyk@...>

Hi,

22 messages 2005/07/12

[#147952] Initialization via a Module — Gavin Kistner <gavin@...>

I have a module that needs to set a few instance variables on the

17 messages 2005/07/13

[#148046] Ruby has ruined my C++ — John Carter <john.carter@...>

These are exciting days in the world of C++. Every month the C/C++ User

52 messages 2005/07/13
[#148152] Re: Ruby has ruined my Java (was Re: Ruby has ruined my C++) — Kero <kero@...> 2005/07/14

> Two!

[#148497] Re: ] Re: Ruby has ruined my Java (was Re: Ruby has ruined my C++) — tony summerfelt <snowzone5@...> 2005/07/17

> After 4 years, Ruby still hasn't ruined itself.

[#148630] Re: ] Re: Ruby has ruined my Java (was Re: Ruby has ruined my C++) — mathew <meta@...> 2005/07/18

tony summerfelt wrote:

[#148709] Re: ] Re: Ruby has ruined my Java (was Re: Ruby has ruined my C++) — Daniel Amelang <daniel.amelang@...> 2005/07/18

Let's say that I have this...friend...um yea. And this 'friend' was

[#148711] Re: ] Re: Ruby has ruined my Java (was Re: Ruby has ruined my C++) — Jacob Fugal <lukfugl@...> 2005/07/18

On 7/18/05, Daniel Amelang <daniel.amelang@gmail.com> wrote:

[#148811] Re: ] Re: Ruby has ruined my Java (was Re: Ruby has ruined my C++) — Kero <kero@...> 2005/07/19

> Ha! You've reproduced my code almost exactly :)

[#148067] Ruby momentum? — Preston Crawford <me@...>

I'm an outsider to the Ruby community. I've used it a time or two,

62 messages 2005/07/14
[#148248] Re: Ruby momentum? — "gregarican" <greg.kujawa@...> 2005/07/15

Zach Dennis wrote:

[#148303] Re: Ruby momentum? — Devin Mullins <twifkak@...> 2005/07/15

Where I work (and I imagine most places), they don't bring developers on

[#148583] Re: Ruby momentum? — tsuraan <tsuraan@...> 2005/07/18

> *Actually when I've mentioned Ruby at work it's inspired more often a

[#148594] Re: Ruby momentum? — Kirk Haines <khaines@...> 2005/07/18

On Monday 18 July 2005 7:41 am, tsuraan wrote:

[#148104] difference? — G畸or SEBESTYノN <segabor@...>

Hi,

15 messages 2005/07/14

[#148229] Sampling (#39) — Ruby Quiz <james@...>

The three rules of Ruby Quiz:

97 messages 2005/07/15
[#148233] Re: [QUIZ] Sampling (#39) — James Edward Gray II <james@...> 2005/07/15

On Jul 15, 2005, at 8:00 AM, Ruby Quiz wrote:

[#148269] Re: [QUIZ] Sampling (#39) — Cassio Pennachin <pennachin@...> 2005/07/15

On 7/15/05, James Edward Gray II <james@grayproductions.net> wrote:

[#148273] Re: [QUIZ] Sampling (#39) — Jim Freeze <jim@...> 2005/07/15

* Cassio Pennachin <pennachin@gmail.com> [2005-07-16 03:04:12 +0900]:

[#148275] Re: [QUIZ] Sampling (#39) — Cassio Pennachin <pennachin@...> 2005/07/15

> Shouldn't those number be more like

[#148276] Re: [QUIZ] Sampling (#39) — Belorion <belorion@...> 2005/07/15

On 7/15/05, Cassio Pennachin <pennachin@gmail.com> wrote:

[#148284] Re: [QUIZ] Sampling (#39) — David Brady <ruby_talk@...> 2005/07/15

Belorion wrote:

[#148317] What does this construct mean? — "Casper" <caspertonka@...>

1. class MyController < ActionController::Base

22 messages 2005/07/16
[#148651] Re: What does this construct mean? — "Casper" <caspertonka@...> 2005/07/18

Devin Mullins wrote:

[#148656] Re: What does this construct mean? — "Ara.T.Howard" <Ara.T.Howard@...> 2005/07/18

On Tue, 19 Jul 2005, Casper wrote:

[#148321] Cascading <=> comparisons — Garance A Drosehn <drosihn@...>

Let's say I have a hash with some values in it, and I want to

15 messages 2005/07/16

[#148338] delaying string evaluation — Navindra Umanee <navindra@...>

Hi,

20 messages 2005/07/16
[#148339] Re: delaying string evaluation — Eric Hodel <drbrain@...7.net> 2005/07/16

On 16 Jul 2005, at 01:23, Navindra Umanee wrote:

[#148361] Re: delaying string evaluation — Navindra Umanee <navindra@...> 2005/07/16

Eric Hodel <drbrain@segment7.net> wrote:

[#148341] Just seen on c.l.py — Stephen Kellett <snail@...>

Hi Folks,

23 messages 2005/07/16
[#148418] Re: Just seen on c.l.py — ptkwt@... (Phil Tomson) 2005/07/16

In article <05th9VCgqN2CFwW4@objmedia.demon.co.uk>,

[#148357] Ruby VS PHP — Tristan Knowles <cydonia_1@...>

I was chatting with a PHP dev friend tonight, he is a

38 messages 2005/07/16
[#148396] Re: Ruby VS PHP — schlu-do@... (Dominik Schlter) 2005/07/16

Hi,

[#148384] `not' in parameter lists — Daniel Brockman <daniel@...>

I just noticed that all of the following give syntax errors:

18 messages 2005/07/16

[#148402] Nonblocking Sockets — James Edward Gray II <james@...>

Is this the "standard" way to make a nonblocking Socket in Ruby?

16 messages 2005/07/16

[#148542] Refactoring Tycho API - Opinions wanted — Hal Fulton <hal9000@...>

I've been revisiting my favorite Ruby project in the past

24 messages 2005/07/18

[#148689] Re: `not' in parameter lists — twifkak@...

On Jul 17, 2005, at 2:34 PM, Daniel Brockman wrote:

13 messages 2005/07/18

[#148721] Ruby/Rails as a starter language? — "SomeDude" <somedude@...>

Hello,

108 messages 2005/07/18
[#148736] Re: Ruby/Rails as a starter language? — vanek@... 2005/07/19

If you don't need to get involved in web programming right away, gawk

[#148743] Re: Ruby/Rails as a starter language? — James Britt <james_b@...> 2005/07/19

vanek@acd.net wrote:

[#148751] Re: Ruby/Rails as a starter language? — Navindra Umanee <navindra@...> 2005/07/19

James Britt <james_b@neurogami.com> wrote:

[#148752] Re: Ruby/Rails as a starter language? — Stefan Lang <langstefan@...> 2005/07/19

On Tuesday 19 July 2005 09:41, Navindra Umanee wrote:

[#148783] Re: Ruby/Rails as a starter language? — Mark Volkmann <r.mark.volkmann@...> 2005/07/19

On 7/19/05, Stefan Lang <langstefan@gmx.at> wrote:

[#148870] Re: Ruby/Rails as a starter language? — Hal Fulton <hal9000@...> 2005/07/19

Mark Volkmann wrote:

[#148873] Re: Ruby/Rails as a starter language? — Daniel Amelang <daniel.amelang@...> 2005/07/19

> In Java, classes aren't objects.

[#148875] Re: Ruby/Rails as a starter language? — Devin Mullins <twifkak@...> 2005/07/19

Daniel Amelang wrote:

[#148880] Re: Ruby/Rails as a starter language? — "Adam P. Jenkins" <thorin@...> 2005/07/20

Devin Mullins wrote:

[#148961] Re: [WAY OT] Re: Ruby/Rails as a starter language? — ptkwt@... (Phil Tomson) 2005/07/20

In article <Pine.LNX.4.62.0507192121430.10750@harp.ngdc.noaa.gov>,

[#148969] Re: [WAY OT] Re: Ruby/Rails as a starter language? — Rick Nooner <rick@...> 2005/07/20

On Thu, Jul 21, 2005 at 02:05:56AM +0900, Phil Tomson wrote:

[#148972] Re: [WAY OT] Re: Ruby/Rails as a starter language? — Jim Freeze <jim@...> 2005/07/20

* Rick Nooner <rick@nooner.net> [2005-07-21 02:59:56 +0900]:

[#148975] Re: [WAY OT] Re: Ruby/Rails as a starter language? — Rick Nooner <rick@...> 2005/07/20

On Thu, Jul 21, 2005 at 03:21:08AM +0900, Jim Freeze wrote:

[#148988] Re: [WAY OT] Re: Ruby/Rails as a starter language? — Jim Freeze <jim@...> 2005/07/20

* Rick Nooner <rick@nooner.net> [2005-07-21 03:57:35 +0900]:

[#148993] Re: [WAY OT] Re: Ruby/Rails as a starter language? — Rick Nooner <rick@...> 2005/07/20

On Thu, Jul 21, 2005 at 04:47:41AM +0900, Jim Freeze wrote:

[#149008] Ruby/OCaml Was Re: [WAY OT] Re: Ruby/Rails as a starter language? — Rick Nooner <rick@...> 2005/07/20

> I was just at the OCaml site,

[#148730] Memory profiling? — Scott Ellsworth <scott@...>

Hi, all.

12 messages 2005/07/19

[#148763] nil for unassigned keys — Simon Strandgaard <neoneye@...>

Sometimes I find myself writing :key=>true,

17 messages 2005/07/19

[#149035] C extension makes things slower — ptkwt@... (Phil Tomson)

In general I've always seen things speed up when I've writtten C

16 messages 2005/07/21

[#149059] Segmentation fault with a threads/forks script — Lucas Nussbaum <lucas@...>

Hi,

13 messages 2005/07/21
[#149069] Re: [BUG] Segmentation fault with a threads/forks script — "Ara.T.Howard" <Ara.T.Howard@...> 2005/07/21

On Thu, 21 Jul 2005, Lucas Nussbaum wrote:

[#149153] FreeRIDE: Where does the output go? — "basi" <basi_lio@...>

I'm trying out FreeRIDE and I have a truly embarrassing question.

15 messages 2005/07/22

[#149184] Drawing Trees (#40) — Ruby Quiz <james@...>

The three rules of Ruby Quiz:

18 messages 2005/07/22

[#149198] Abstract class or interface? — EdUarDo <eduardo.yanezNOSPAM@...>

Hi all again :),

13 messages 2005/07/22

[#149286] Local Instance Methods — "Trans" <transfire@...>

Hi All--

25 messages 2005/07/23

[#149302] Any interest in writing gui library on top of qtruby? — meruby@...

wax is a gui written on top of wxPython. It allows seamless integration

19 messages 2005/07/23

[#149322] Lisp on Lines — "luke" <lduncalfe@...>

Read on the comp.lang.lisp group that someone is developing 'Lisp on Lines'

44 messages 2005/07/24
[#149343] Re: Lisp on Lines — "Ara.T.Howard" <Ara.T.Howard@...> 2005/07/24

On Sun, 24 Jul 2005, luke wrote:

[#149366] Re: Lisp on Lines — "William James" <w_a_x_man@...> 2005/07/24

How much less powerful than Lisp is Ruby?

[#149397] Nitro + Og 0.21.0 Compiler, Og custom joins, Og dynamic injection, new builder — "George Moschovitis" <george.moschovitis@...>

Hello everyone,

13 messages 2005/07/25

[#149481] What's so special about operators, built-in classes and modules? — Jim Freeze <jim@...>

I just noticed this little quirk. Is there something

30 messages 2005/07/25

[#149490] Trying to understand symbols — "Sam Kong" <sam.s.kong@...>

Hello!

18 messages 2005/07/25

[#149515] Factory Patterns in Ruby — Lyndon Samson <lyndon.samson@...>

Factory is a very common pattern in the java world, in some places

17 messages 2005/07/26

[#149555] — "Adrian Petru Dimulescu" <adrian.dimulescu@...>

Hello,

13 messages 2005/07/26

[#149616] Next Official Ruby Version

Is it somehow planned to build a new official Ruby before Ruby 2, that means a version called 1.10 or so?

26 messages 2005/07/26

[#149654] (X)Emacs users going to RubyCOnf — Forrest Chang <fkc_email-news@...>

Hi All:

14 messages 2005/07/27

[#149720] Re: What's so special about operators, built-in classes and modules? — twifkak@...

>Then you will have complex network of classes instead of simple tree

56 messages 2005/07/27
[#149765] Re: What's so special about operators, built-in classes and modules? — Daniel Brockman <daniel@...> 2005/07/28

gabriele renzi <surrender_it@remove-yahoo.it> writes:

[#149770] Re: What's so special about operators, built-in classes and modules? — Yukihiro Matsumoto <matz@...> 2005/07/28

Hi,

[#149772] Re: What's so special about operators, built-in classes and modules? — Devin Mullins <twifkak@...> 2005/07/28

Yukihiro Matsumoto wrote:

[#149773] Re: What's so special about operators, built-in classes and modules? — Yukihiro Matsumoto <matz@...> 2005/07/28

Hi,

[#149776] Re: What's so special about operators, built-in classes and modules? — Devin Mullins <twifkak@...> 2005/07/28

Yukihiro Matsumoto wrote:

[#149905] Re: What's so special about operators, built-in classes and modules? — Daniel Brockman <daniel@...> 2005/07/28

Yukihiro Matsumoto <matz@ruby-lang.org> writes:

[#149783] Ruby in embedded applications — "treefrog" <stephen.hill@...>

Hi folks,

14 messages 2005/07/28

[#149793] Idea for Ruby 2.0 — Nikolai Weibull <mailing-lists.ruby-talk@...>

Lately I've found myself using pseudo-anonymous variables a lot, e.g.,

24 messages 2005/07/28

[#149801] Combination of two arrays — Claus Spitzer <docboobenstein@...>

Greetings!

18 messages 2005/07/28

[#149876] Linux Journal article on Ruby — pat eyler <pat.eyler@...>

http://www.linuxjournal.com/article/8356 it's always nice to see another

13 messages 2005/07/28

[#149968] Which Regex-Engine will be used in Ruby 1.8.3 Release?

One short question.

12 messages 2005/07/29

[#149982] Chopping the beginning of a string elegantly — "francisrammeloo@..." <francisrammeloo@...>

Hi all,

13 messages 2005/07/29

[#150133] Ruby-Python; using python from within ruby — "Norjee" <Norjee@...>

At the moment I'm looking at rails, it seems like a great framework.

13 messages 2005/07/30

[#150154] Ruby-Oniguruma interoperability on Named Groups

Let me first explain the reason for and the kind of this message.

10 messages 2005/07/30

[#150205] Yet Another useless Ruby 2 Idea — gabriele renzi <surrender_it@...>

Hi gurus and nubys,

69 messages 2005/07/31
[#150680] Re: Yet Another useless Ruby 2 Idea — Daniel Brockman <daniel@...> 2005/08/04

Jeff Wood <jeff.darklight@gmail.com> writes:

[#150684] Re: Yet Another useless Ruby 2 Idea — Austin Ziegler <halostatue@...> 2005/08/04

On 8/3/05, Daniel Brockman <daniel@brockman.se> wrote:

[#150688] Re: Yet Another useless Ruby 2 Idea — Jeff Wood <jeff.darklight@...> 2005/08/04

I'm not saying there are NO features of python that are cool... I like

[#150860] Re: Yet Another useless Ruby 2 Idea — gabriele renzi <surrender_it@...> 2005/08/05

Jeff Wood ha scritto:

[#150899] Re: Yet Another useless Ruby 2 Idea — Jacob Fugal <lukfugl@...> 2005/08/05

On 8/5/05, gabriele renzi <surrender_it@remove-yahoo.it> wrote:

[#150910] Re: Yet Another useless Ruby 2 Idea — gabriele renzi <surrender_it@...> 2005/08/05

Jacob Fugal ha scritto:

[#151275] Re: Yet Another useless Ruby 2 Idea — mathew <meta@...> 2005/08/08

gabriele renzi wrote:

[#151354] Re: Yet Another useless Ruby 2 Idea — gabriele renzi <surrender_it@...> 2005/08/09

mathew ha scritto:

Re: accessing index inside map

From: nobuyoshi nakada <nobuyoshi.nakada@...>
Date: 2005-07-11 07:41:45 UTC
List: ruby-talk #147736
Hi,

At Mon, 11 Jul 2005 14:57:00 +0900,
Yukihiro Matsumoto wrote in [ruby-talk:147731]:
> |  $ ./ruby -renumerator -e 'p (1..6).to_enum.with_index{|x,i|p [x,i]}'
> |  [1, 0]
> |  [2, 1]
> |  [3, 2]
> |  [4, 3]
> |  [5, 4]
> |  [6, 5]
> |  1..6
> |
> |A patch based on the current implementation.
> 
> Can you commit this patch to the HEAD?

For performance, I'd like to make Enumerator a subclass of
Data instead of Object, in the HEAD.


Index: ext/enumerator/enumerator.c
===================================================================
RCS file: /cvs/ruby/src/ruby/ext/enumerator/enumerator.c,v
retrieving revision 1.5
diff -U2 -p -r1.5 enumerator.c
--- ext/enumerator/enumerator.c	2 Nov 2004 07:38:21 -0000	1.5
+++ ext/enumerator/enumerator.c	11 Jul 2005 07:38:27 -0000
@@ -18,5 +18,77 @@
 static VALUE rb_cEnumerator;
 static ID sym_each, sym_each_with_index, sym_each_slice, sym_each_cons;
-static ID id_new, id_enum_obj, id_enum_method, id_enum_args;
+#if !defined(HAVE_RB_PROC_CALL) || !defined(HAVE_RB_METHOD_CALL)
+static ID id_call;
+#endif
+
+static VALUE
+proc_call(proc, args)
+    VALUE proc, args;
+{
+#ifdef HAVE_RB_PROC_CALL
+    if (TYPE(args) != T_ARRAY) {
+	args = rb_values_new(1, args);
+    }
+    return rb_proc_call(proc, args);
+#else
+    return rb_funcall2(proc, id_call, 1, &args);
+#endif
+}
+
+static VALUE
+method_call(method, args)
+    VALUE method, args;
+{
+#ifdef HAVE_RB_METHOD_CALL
+    return rb_method_call(RARRAY(args)->len, RARRAY(args)->ptr, method);
+#else
+    return rb_funcall2(method, id_call, RARRAY(args)->len, RARRAY(args)->ptr);
+#endif
+}
+
+struct enumerator {
+    VALUE method;
+    VALUE proc;
+    VALUE args;
+    VALUE (*iter)_((VALUE, struct enumerator *));
+};
+
+static void enumerator_mark _((void *));
+static void
+enumerator_mark(p)
+    void *p;
+{
+    struct enumerator *ptr = p;
+    rb_gc_mark(ptr->method);
+    rb_gc_mark(ptr->proc);
+    rb_gc_mark(ptr->args);
+}
+
+static struct enumerator *
+enumerator_ptr(obj)
+    VALUE obj;
+{
+    struct enumerator *ptr;
+
+    Data_Get_Struct(obj, struct enumerator, ptr);
+    if (RDATA(obj)->dmark != enumerator_mark) {
+	rb_raise(rb_eTypeError,
+		 "wrong argument type %s (expected Enumerable::Enumerator)",
+		 rb_obj_classname(obj));
+    }
+    if (!ptr) {
+	rb_raise(rb_eArgError, "uninitialized enumerator");
+    }
+    return ptr;
+}
+
+static VALUE enumerator_iter_i _((VALUE, struct enumerator *));
+static VALUE
+enumerator_iter_i(i, e)
+    VALUE i;
+    struct enumerator *e;
+{
+    return rb_yield(proc_call(e->proc, i));
+}
 
 static VALUE
@@ -26,5 +98,7 @@ obj_to_enum(obj, enum_args)
     rb_ary_unshift(enum_args, obj);
 
-    return rb_apply(rb_cEnumerator, id_new, enum_args);
+    return rb_class_new_instance(RARRAY(enum_args)->len,
+				 RARRAY(enum_args)->ptr,
+				 rb_cEnumerator);
 }
 
@@ -33,5 +107,8 @@ enumerator_enum_with_index(obj)
     VALUE obj;
 {
-    return rb_funcall(rb_cEnumerator, id_new, 2, obj, sym_each_with_index);
+    VALUE args[2];
+    args[0] = obj;
+    args[1] = sym_each_with_index;
+    return rb_class_new_instance(2, args, rb_cEnumerator);
 }
 
@@ -39,8 +116,8 @@ static VALUE
 each_slice_i(val, memo)
     VALUE val;
-    NODE *memo;
+    VALUE *memo;
 {
-    VALUE ary = memo->u1.value;
-    long size = memo->u3.cnt;
+    VALUE ary = memo[0];
+    long size = (long)memo[1];
 
     rb_ary_push(ary, val);
@@ -48,5 +125,5 @@ each_slice_i(val, memo)
     if (RARRAY(ary)->len == size) {
 	rb_yield(ary);
-	memo->u1.value = rb_ary_new2(size);
+	memo[0] = rb_ary_new2(size);
     }
 
@@ -59,14 +136,14 @@ enum_each_slice(obj, n)
 {
     long size = NUM2LONG(n);
-    NODE *memo;
-    VALUE ary;
+    VALUE args[2], ary;
 
     if (size <= 0) rb_raise(rb_eArgError, "invalid slice size");
 
-    memo = rb_node_newnode(NODE_MEMO, rb_ary_new2(size), 0, size);
+    args[0] = rb_ary_new2(size);
+    args[1] = (VALUE)size;
 
-    rb_iterate(rb_each, obj, each_slice_i, (VALUE)memo);
+    rb_iterate(rb_each, obj, each_slice_i, (VALUE)args);
 
-    ary = memo->u1.value;
+    ary = args[0];
     if (RARRAY(ary)->len > 0) rb_yield(ary);
 
@@ -78,5 +155,9 @@ enumerator_enum_slice(obj, n)
     VALUE obj, n;
 {
-    return rb_funcall(rb_cEnumerator, id_new, 3, obj, sym_each_slice, n);
+    VALUE args[2];
+    args[0] = obj;
+    args[1] = sym_each_slice;
+    args[2] = n;
+    return rb_class_new_instance(3, args, rb_cEnumerator);
 }
 
@@ -84,8 +165,8 @@ static VALUE
 each_cons_i(val, memo)
     VALUE val;
-    NODE *memo;
+    VALUE *memo;
 {
-    VALUE ary = memo->u1.value;
-    long size = memo->u3.cnt;
+    VALUE ary = memo[0];
+    long size = (long)memo[1];
 
     if (RARRAY(ary)->len == size) {
@@ -104,10 +185,11 @@ enum_each_cons(obj, n)
 {
     long size = NUM2LONG(n);
-    NODE *memo;
+    VALUE args[2];
 
     if (size <= 0) rb_raise(rb_eArgError, "invalid size");
-    memo = rb_node_newnode(NODE_MEMO, rb_ary_new2(size), 0, size);
+    args[0] = rb_ary_new2(size);
+    args[1] = (VALUE)size;
 
-    rb_iterate(rb_each, obj, each_cons_i, (VALUE)memo);
+    rb_iterate(rb_each, obj, each_cons_i, (VALUE)args);
 
     return Qnil;
@@ -118,5 +200,19 @@ enumerator_enum_cons(obj, n)
     VALUE obj, n;
 {
-    return rb_funcall(rb_cEnumerator, id_new, 3, obj, sym_each_cons, n);
+    VALUE args[2];
+    args[0] = obj;
+    args[1] = sym_each_cons;
+    args[2] = n;
+    return rb_class_new_instance(3, args, rb_cEnumerator);
+}
+
+static VALUE enumerator_allocate _((VALUE));
+static VALUE
+enumerator_allocate(klass)
+    VALUE klass;
+{
+    struct enumerator *ptr;
+    return Data_Make_Struct(rb_cEnumerator, struct enumerator,
+			    enumerator_mark, -1, ptr);
 }
 
@@ -128,4 +224,5 @@ enumerator_initialize(argc, argv, obj)
 {
     VALUE enum_obj, enum_method, enum_args;
+    struct enumerator *ptr = enumerator_ptr(obj);
 
     rb_scan_args(argc, argv, "11*", &enum_obj, &enum_method, &enum_args);
@@ -134,16 +231,25 @@ enumerator_initialize(argc, argv, obj)
 	enum_method = sym_each;
 
-    rb_ivar_set(obj, id_enum_obj, enum_obj);
-    rb_ivar_set(obj, id_enum_method, enum_method);
-    rb_ivar_set(obj, id_enum_args, enum_args);
+    ptr->method = rb_obj_method(enum_obj, enum_method);
+    if (rb_block_given_p()) {
+	ptr->proc = rb_block_proc();
+	ptr->iter = enumerator_iter_i;
+    }
+    else {
+	ptr->iter = (VALUE (*) _((VALUE, struct enumerator *)))rb_yield;
+    }
+    ptr->args = enum_args;
 
-    return Qnil;
+    return obj;
 }
 
+static VALUE enumerator_iter _((VALUE));
 static VALUE
 enumerator_iter(memo)
-    NODE *memo;
+    VALUE memo;
 {
-    return rb_apply(memo->u1.value, memo->u2.id, memo->u3.value);
+    struct enumerator *e = (struct enumerator *)memo;
+
+    return method_call(e->method, e->args);
 }
 
@@ -152,14 +258,29 @@ enumerator_each(obj)
     VALUE obj;
 {
-    VALUE val;
+    struct enumerator *e = enumerator_ptr(obj);
 
-    obj = (VALUE)rb_node_newnode(NODE_MEMO,
-				 rb_ivar_get(obj, id_enum_obj),
-				 rb_to_id(rb_ivar_get(obj, id_enum_method)),
-				 rb_ivar_get(obj, id_enum_args));
-    val = rb_iterate((VALUE (*)_((VALUE)))enumerator_iter, obj, rb_yield, 0);
+    return rb_iterate(enumerator_iter, (VALUE)e, e->iter, (VALUE)e);
+}
+
+static VALUE
+enumerator_with_index_i(val, memo)
+    VALUE val, *memo;
+{
+    val = rb_yield_values(2, val, INT2FIX(*memo));
+    ++*memo;
     return val;
 }
 
+static VALUE
+enumerator_with_index(obj)
+    VALUE obj;
+{
+    struct enumerator *e = enumerator_ptr(obj);
+    VALUE memo = 0;
+
+    return rb_iterate(enumerator_iter, (VALUE)e,
+		      enumerator_with_index_i, (VALUE)&memo);
+}
+
 void
 Init_enumerator()
@@ -181,6 +302,8 @@ Init_enumerator()
     rb_include_module(rb_cEnumerator, rb_mEnumerable);
 
+    rb_define_alloc_func(rb_cEnumerator, enumerator_allocate);
     rb_define_method(rb_cEnumerator, "initialize", enumerator_initialize, -1);
     rb_define_method(rb_cEnumerator, "each", enumerator_each, 0);
+    rb_define_method(rb_cEnumerator, "with_index", enumerator_with_index, 0);
 
     sym_each		= ID2SYM(rb_intern("each"));
@@ -189,7 +312,6 @@ Init_enumerator()
     sym_each_cons	= ID2SYM(rb_intern("each_cons"));
 
-    id_new		= rb_intern("new");
-    id_enum_obj		= rb_intern("enum_obj");
-    id_enum_method	= rb_intern("enum_method");
-    id_enum_args	= rb_intern("enum_args");
+#if !defined(HAVE_RB_PROC_CALL) || !defined(HAVE_RB_METHOD_CALL)
+    id_call = rb_intern("call");
+#endif
 }
Index: ext/enumerator/extconf.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/ext/enumerator/extconf.rb,v
retrieving revision 1.1
diff -U2 -p -r1.1 extconf.rb
--- ext/enumerator/extconf.rb	1 Nov 2004 05:04:04 -0000	1.1
+++ ext/enumerator/extconf.rb	23 Jun 2005 02:55:54 -0000
@@ -1,2 +1,5 @@
 require 'mkmf'
+
+%w"rb_obj_method rb_method_call".all? {|f| have_func(f, "ruby.h")}
+have_func("rb_proc_call", "ruby.h")
 create_makefile('enumerator')


-- 
Nobu Nakada

In This Thread