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..13c4ab473df7 100644 --- a/core/src/main/ruby/jruby/kernel/kernel.rb +++ b/core/src/main/ruby/jruby/kernel/kernel.rb @@ -1,16 +1,22 @@ 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(&b) + # workaround for yield to lambda not triggering arity error + # see https://bugs.ruby-lang.org/issues/12705 + b.lambda? ? b.call(self) : yield(self) + self + end end