aboutsummaryrefslogtreecommitdiffstats
path: root/enumerator.c
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-24 15:53:38 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-24 15:53:38 +0000
commit0c9f66eb400a78ef2e201a30a3904f59033d0439 (patch)
treeae660e8809aba0e8ffd7c8b1b1d8d41c063db6ab /enumerator.c
parentfa288063e0159374a9a5f06a4d9b52785778b926 (diff)
downloadruby-0c9f66eb400a78ef2e201a30a3904f59033d0439.tar.gz
* enumerator (lazy_initialize): set the instance variable "receiver"
to include the receiver to the return value of inspect on a lazy enumerator directly created by Enumerator::Lazy.new. * enumerator (RETURN_LAZY): don't set the instance variable "receiver". git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enumerator.c')
-rw-r--r--enumerator.c30
1 files changed, 8 insertions, 22 deletions
diff --git a/enumerator.c b/enumerator.c
index c7d3d799e4..cc19cacfed 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -1244,31 +1244,17 @@ lazy_initialize(int argc, VALUE *argv, VALUE self)
(rb_block_given_p() ? lazy_init_block_i : lazy_init_block),
obj);
enumerator_init(self, generator, meth, argc - offset, argv + offset);
+ rb_iv_set(self, "receiver", obj);
return self;
}
-static void
-lazy_set_inspection_data(VALUE obj, VALUE receiver, VALUE method)
-{
- rb_iv_set(obj, "receiver", receiver);
- if (NIL_P(method)) {
- ID id = rb_frame_this_func();
- rb_iv_set(obj, "method", ID2SYM(id));
- }
- else {
- rb_iv_set(obj, "method", method);
- }
-}
-
-/*
- * An ugly macro to set inspection data to arg, and return arg.
- * RETURN_LAZY assumes that the reciver is obj.
- */
-#define RETURN_LAZY(arg) do { \
- VALUE lazy = arg; \
- lazy_set_inspection_data(lazy, obj, Qnil); \
- return lazy; \
+/* A macro to set the current method name to lazy and return lazy. */
+#define RETURN_LAZY(lazy) do { \
+ VALUE result = lazy; \
+ ID id = rb_frame_this_func(); \
+ rb_iv_set(result, "method", ID2SYM(id)); \
+ return result; \
} while (0)
/*
@@ -1309,7 +1295,7 @@ enumerable_lazy(VALUE obj)
result = rb_class_new_instance(1, &obj, rb_cLazy);
/* Qfalse indicates that the Enumerator::Lazy has no method name */
- lazy_set_inspection_data(result, obj, Qfalse);
+ rb_iv_set(result, "method", Qfalse);
return result;
}