From: Robert Dober Date: 2009-07-19T01:10:09+09:00 Subject: Re: Enumerator of what? Not as far as I know, but this patch could do it if you really need it --- enumerator.c 2009-04-19 15:33:31.000000000 +0200 +++ enumerator-with-obj-access.c 2009-07-18 18:02:33.000000000 +0200 @@ -537,6 +537,12 @@ return v; } +static VALUE +enumerator_get_object( VALUE obj ) +{ + return enumerator_ptr( obj )->obj; +} + /* * call-seq: * e.rewind => e @@ -788,6 +794,7 @@ rb_define_method(rb_cEnumerator, "initialize", enumerator_initialize, -1); rb_define_method(rb_cEnumerator, "initialize_copy", enumerator_init_copy, 1); rb_define_method(rb_cEnumerator, "each", enumerator_each, 0); + rb_define_method(rb_cEnumerator, "get_object", enumerator_get_object, 0); rb_define_method(rb_cEnumerator, "each_with_index", enumerator_with_index, 0); rb_define_method(rb_cEnumerator, "each_with_object", enumerator_with_object, 1); rb_define_method(rb_cEnumerator, "with_index", enumerator_with_index, 0); please note that 2.times.get_object will give you 2 and not [0, 1] which 2.times.to_a would give you. Cheers Robert On 7/18/09, Intransition wrote: > Any way to ask an Enumerator what the underlying object it is > enumerating for is? Eg. > > e = Enumerator.new([1,2,3], :each) > e.some_method #=> [1,2,3] > > > -- Toutes les grandes personnes ont d’abord été des enfants, mais peu d’entre elles s’en souviennent. All adults have been children first, but not many remember. [Antoine de Saint-Exupéry]