Skip to content

Commit

Permalink
Move Kernel#tap into Ruby
Browse files Browse the repository at this point in the history
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 jruby#6430
  • Loading branch information
headius committed Oct 10, 2023
1 parent 641a091 commit 02b6ee6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
21 changes: 11 additions & 10 deletions core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
12 changes: 8 additions & 4 deletions core/src/main/ruby/jruby/kernel/kernel.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 02b6ee6

Please sign in to comment.