@@ -794,6 +794,54 @@ enumerator_inspect(VALUE obj)
794
794
return rb_exec_recursive (inspect_enumerator , obj , 0 );
795
795
}
796
796
797
+ /*
798
+ * call-seq:
799
+ * e.receiver -> obj
800
+ *
801
+ * Returns the object that <i>e</i> will call when iterated.
802
+ *
803
+ * "hello".to_enum(:gsub, /l/).receiver # => "hello"
804
+ */
805
+
806
+ static VALUE
807
+ enumerator_receiver (VALUE obj )
808
+ {
809
+ return enumerator_ptr (obj )-> obj ;
810
+ }
811
+
812
+ /*
813
+ * call-seq:
814
+ * e.method -> sym
815
+ *
816
+ * Returns the method that <i>e</i> will send when iterated.
817
+ *
818
+ * "hello".to_enum(:gsub, /l/).method # => :gsub
819
+ */
820
+
821
+ static VALUE
822
+ enumerator_method (VALUE obj )
823
+ {
824
+ return ID2SYM (enumerator_ptr (obj )-> meth );
825
+ }
826
+
827
+ /*
828
+ * call-seq:
829
+ * e.arguments -> ary
830
+ *
831
+ * Returns the arguments that <i>e</i> will send when iterated.
832
+ *
833
+ * "hello".to_enum(:gsub, /l/).arguments # => [/l/]
834
+ */
835
+
836
+ static VALUE
837
+ enumerator_arguments (VALUE obj )
838
+ {
839
+ VALUE dup , args = enumerator_ptr (obj )-> args ;
840
+ if (!args ) return rb_ary_new2 (0 );
841
+ dup = rb_ary_new2 (RARRAY_LEN (args ));
842
+ return rb_ary_replace (dup , args );
843
+ }
844
+
797
845
/*
798
846
* Yielder
799
847
*/
@@ -1099,6 +1147,9 @@ Init_Enumerator(void)
1099
1147
rb_define_method (rb_cEnumerator , "feed" , enumerator_feed , 1 );
1100
1148
rb_define_method (rb_cEnumerator , "rewind" , enumerator_rewind , 0 );
1101
1149
rb_define_method (rb_cEnumerator , "inspect" , enumerator_inspect , 0 );
1150
+ rb_define_method (rb_cEnumerator , "receiver" , enumerator_receiver , 0 );
1151
+ rb_define_method (rb_cEnumerator , "method" , enumerator_method , 0 );
1152
+ rb_define_method (rb_cEnumerator , "arguments" , enumerator_arguments , 0 );
1102
1153
1103
1154
rb_eStopIteration = rb_define_class ("StopIteration" , rb_eIndexError );
1104
1155
rb_define_method (rb_eStopIteration , "result" , stop_result , 0 );
0 commit comments