Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Kernel#respond_to_missing? #1518

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions core/kernel.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2806,6 +2806,23 @@ module Kernel : BasicObject
#
def respond_to?: (interned name, ?boolish include_all) -> bool

# <!--
# rdoc-file=vm_method.c
# - obj.respond_to_missing?(symbol, include_all) -> true or false
# - obj.respond_to_missing?(string, include_all) -> true or false
# -->
# DO NOT USE THIS DIRECTLY.
#
# Hook method to return whether the *obj* can respond to *id* method or not.
#
# When the method name parameter is given as a string, the string is converted
# to a symbol.
#
# See #respond_to?, and the example of BasicObject.
#
%a{annotate:rdoc:copy:Object#respond_to_missing?}
private def respond_to_missing?: (Symbol, bool) -> bool

# <!--
# rdoc-file=vm_eval.c
# - foo.send(symbol [, args...]) -> obj
Expand Down
11 changes: 11 additions & 0 deletions test/stdlib/Kernel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -941,4 +941,15 @@ def test_define_singleton_method
Object.instance_method(:to_s)
)
end

def test_respond_to_missing?
obj = Object.new

# The default implementation always returns `false` regardless of the args,
# let alone their types; though overrides only have to support Symbol + bool
assert_send_type(
"(::Symbol, bool) -> bool",
obj, :respond_to_missing?, :to_s, true
)
end
end