/* * call-seq: * obj.to_enum(method = :each, *args) * obj.enum_for(method = :each, *args) * * Returns Enumerator.new(self, method, *args). * * e.g.: * * str = "xyz" * * enum = str.enum_for(:each_byte) * a = enum.map {|b| '%02x' % b } #=> ["78", "79", "7a"] * * # protects an array from being modified * a = [1, 2, 3] * some_method(a.to_enum) * */ static VALUE obj_to_enum(int argc, VALUE *argv, VALUE obj) { VALUE meth = sym_each; if (argc > 0) { --argc; meth = *argv++; } return rb_enumeratorize(obj, meth, argc, argv); }
/* * call-seq: * obj.to_enum(method = :each, *args) * obj.enum_for(method = :each, *args) * * Returns Enumerator.new(self, method, *args). * * e.g.: * * str = "xyz" * * enum = str.enum_for(:each_byte) * a = enum.map {|b| '%02x' % b } #=> ["78", "79", "7a"] * * # protects an array from being modified * a = [1, 2, 3] * some_method(a.to_enum) * */ static VALUE obj_to_enum(VALUE obj, SEL sel, int argc, VALUE *argv) { VALUE meth = sym_each; if (argc > 0) { --argc; meth = *argv++; } ID meth_id = rb_to_id(meth); SEL enum_sel = rb_vm_id_to_sel(meth_id, argc); return rb_enumeratorize(obj, enum_sel, argc, argv); }