From 02b6ee66118180a5d99bc292831395b6469b0986 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 10 Oct 2023 16:45:29 -0500 Subject: [PATCH] Move Kernel#tap into Ruby The Java version did little more than yield to the given block, and the new specs provided for Kernel#warn skipping internal files expects that Kernel#tap will come from an internal file. See #6430 --- core/src/main/java/org/jruby/RubyKernel.java | 21 ++++++++++---------- core/src/main/ruby/jruby/kernel/kernel.rb | 12 +++++++---- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/jruby/RubyKernel.java b/core/src/main/java/org/jruby/RubyKernel.java index 5146f40a73e6..f69b5a46fd3d 100644 --- a/core/src/main/java/org/jruby/RubyKernel.java +++ b/core/src/main/java/org/jruby/RubyKernel.java @@ -2028,16 +2028,6 @@ public static IRubyObject fork19(ThreadContext context, IRubyObject recv, Block return fork(context, recv, block); } - @JRubyMethod(module = true) - public static IRubyObject tap(ThreadContext context, IRubyObject recv, Block block) { - if (block.getProcObject() != null) { - block.getProcObject().call(context, recv); - } else { - block.yield(context, recv); - } - return recv; - } - @JRubyMethod(name = {"to_enum", "enum_for"}, rest = true, keywords = true) public static IRubyObject obj_to_enum(final ThreadContext context, IRubyObject self, IRubyObject[] args, final Block block) { // to_enum is a bit strange in that it will propagate the arguments it passes to each element it calls. We are determining @@ -2644,4 +2634,15 @@ public static IRubyObject method(IRubyObject self, IRubyObject symbol) { public static IRubyObject method19(IRubyObject self, IRubyObject symbol) { return method(self, symbol); } + + // defined in Ruby now but left here for backward compat + @Deprecated + public static IRubyObject tap(ThreadContext context, IRubyObject recv, Block block) { + if (block.getProcObject() != null) { + block.getProcObject().call(context, recv); + } else { + block.yield(context, recv); + } + return recv; + } } diff --git a/core/src/main/ruby/jruby/kernel/kernel.rb b/core/src/main/ruby/jruby/kernel/kernel.rb index b48a586b21e1..92093264e256 100644 --- a/core/src/main/ruby/jruby/kernel/kernel.rb +++ b/core/src/main/ruby/jruby/kernel/kernel.rb @@ -1,16 +1,20 @@ module Kernel - module_function - def exec(*args) + module_function def exec(*args) _exec_internal(*JRuby::ProcessUtil.exec_args(args)) end # Replaces Java version for better caching - def initialize_dup(original) + module_function def initialize_dup(original) initialize_copy(original) end # Replaces Java version for better caching - def initialize_clone(original, freeze: false) + module_function def initialize_clone(original, freeze: false) initialize_copy(original) end + + def tap + yield(self) + self + end end