* 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
This commit is contained in:
parent
fa288063e0
commit
0c9f66eb40
@ -1,3 +1,11 @@
|
|||||||
|
Sun Mar 25 00:46:06 2012 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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".
|
||||||
|
|
||||||
Sat Mar 24 23:59:00 2012 Shugo Maeda <shugo@ruby-lang.org>
|
Sat Mar 24 23:59:00 2012 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
* enumerator (enumerator_inspect): include the original receiver and
|
* enumerator (enumerator_inspect): include the original receiver and
|
||||||
|
30
enumerator.c
30
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),
|
(rb_block_given_p() ? lazy_init_block_i : lazy_init_block),
|
||||||
obj);
|
obj);
|
||||||
enumerator_init(self, generator, meth, argc - offset, argv + offset);
|
enumerator_init(self, generator, meth, argc - offset, argv + offset);
|
||||||
|
rb_iv_set(self, "receiver", obj);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
/* A macro to set the current method name to lazy and return lazy. */
|
||||||
lazy_set_inspection_data(VALUE obj, VALUE receiver, VALUE method)
|
#define RETURN_LAZY(lazy) do { \
|
||||||
{
|
VALUE result = lazy; \
|
||||||
rb_iv_set(obj, "receiver", receiver);
|
ID id = rb_frame_this_func(); \
|
||||||
if (NIL_P(method)) {
|
rb_iv_set(result, "method", ID2SYM(id)); \
|
||||||
ID id = rb_frame_this_func();
|
return result; \
|
||||||
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; \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1309,7 +1295,7 @@ enumerable_lazy(VALUE obj)
|
|||||||
|
|
||||||
result = rb_class_new_instance(1, &obj, rb_cLazy);
|
result = rb_class_new_instance(1, &obj, rb_cLazy);
|
||||||
/* Qfalse indicates that the Enumerator::Lazy has no method name */
|
/* 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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,6 +282,10 @@ class TestLazyEnumerator < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_inspect
|
def test_inspect
|
||||||
|
assert_equal("#<Enumerator::Lazy: 1..10:each>",
|
||||||
|
Enumerator::Lazy.new(1..10).inspect)
|
||||||
|
assert_equal("#<Enumerator::Lazy: 1..10:cycle(2)>",
|
||||||
|
Enumerator::Lazy.new(1..10, :cycle, 2).inspect)
|
||||||
assert_equal("#<Enumerator::Lazy: 1..10>", (1..10).lazy.inspect)
|
assert_equal("#<Enumerator::Lazy: 1..10>", (1..10).lazy.inspect)
|
||||||
assert_equal('#<Enumerator::Lazy: #<Enumerator: "foo":chars>>',
|
assert_equal('#<Enumerator::Lazy: #<Enumerator: "foo":chars>>',
|
||||||
"foo".chars.lazy.inspect)
|
"foo".chars.lazy.inspect)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user