From f3a0d7a2035e9f5e0c70effd55732607e3def263 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Fri, 3 Jul 2020 09:52:35 -0700 Subject: Rewrite Kernel#tap with Ruby (#3281) * Rewrite Kernel#tap with Ruby This was good for VM too, but of course my intention is to unblock JIT's inlining of a block over yield (inlining invokeyield has not been committed though). * Fix test_settracefunc About the :tap deletions, the :tap events are actually traced (we already have a TracePoint test for builtin methods), but it's filtered out by tp.path == "xyzzy" (it became ""). We could trace tp.path == "" cases too, but the lineno is impacted by kernel.rb changes and I didn't want to make it fragile for kernel.rb lineno changes. --- object.c | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index c4a0d3c7ee..4718fad66f 100644 --- a/object.c +++ b/object.c @@ -938,31 +938,6 @@ rb_class_search_ancestor(VALUE cl, VALUE c) return class_search_ancestor(cl, RCLASS_ORIGIN(c)); } -/** - * call-seq: - * obj.tap {|x| block } -> obj - * - * Yields self to the block, and then returns self. - * The primary purpose of this method is to "tap into" a method chain, - * in order to perform operations on intermediate results within the chain. - * - * (1..10) .tap {|x| puts "original: #{x}" } - * .to_a .tap {|x| puts "array: #{x}" } - * .select {|x| x.even? } .tap {|x| puts "evens: #{x}" } - * .map {|x| x*x } .tap {|x| puts "squares: #{x}" } - * - *-- - * \private - *++ - */ - -VALUE -rb_obj_tap(VALUE obj) -{ - rb_yield(obj); - return obj; -} - /* * Document-method: inherited @@ -4638,7 +4613,6 @@ InitVM_Object(void) rb_define_method(rb_mKernel, "instance_of?", rb_obj_is_instance_of, 1); rb_define_method(rb_mKernel, "kind_of?", rb_obj_is_kind_of, 1); rb_define_method(rb_mKernel, "is_a?", rb_obj_is_kind_of, 1); - rb_define_method(rb_mKernel, "tap", rb_obj_tap, 0); rb_define_global_function("sprintf", f_sprintf, -1); rb_define_global_function("format", f_sprintf, -1); -- cgit v1.2.3