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

Let define_singleton_method accept a proc #1431

Merged
merged 2 commits into from
Aug 18, 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
4 changes: 2 additions & 2 deletions core/module.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,8 @@ class Module < Object
# I'm Dino!
# #<B:0x401b39e8>
#
def define_method: (id arg0, ?Proc | Method | UnboundMethod arg1) -> Symbol
| (id arg0) { () -> untyped } -> Symbol
def define_method: (id symbol, Proc | Method | UnboundMethod method) -> Symbol
| (id symbol) { () -> untyped } -> Symbol

# <!--
# rdoc-file=object.c
Expand Down
2 changes: 1 addition & 1 deletion core/object.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class Object < BasicObject
# chris.define_singleton_method(:greet) {|greeting| "#{greeting}, I'm Chris!" }
# chris.greet("Hi") #=> "Hi, I'm Chris!"
#
def define_singleton_method: (name, Method | UnboundMethod) -> Symbol
def define_singleton_method: (name, Method | UnboundMethod | Proc method) -> Symbol
| (name) { (*untyped) -> untyped } -> Symbol

# <!--
Expand Down
38 changes: 38 additions & 0 deletions test/stdlib/Object_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,41 @@ def test_to_s
Object.new.to_s
end
end


class ObjectInstanceTest < Test::Unit::TestCase
include TypeAssertions

testing "::Object"

def test_define_singleton_method
obj = Object.new

assert_send_type(
"(::Symbol) { () -> void } -> Symbol",
obj, :define_singleton_method,
:foo
) do end

assert_send_type(
"(::Symbol, ::Proc) -> Symbol",
obj, :define_singleton_method,
:bar,
-> {}
)

assert_send_type(
"(::Symbol, ::Method) -> Symbol",
obj, :define_singleton_method,
:bar,
obj.method(:to_s)
)

assert_send_type(
"(::Symbol, ::UnboundMethod) -> Symbol",
obj, :define_singleton_method,
:bar,
Object.instance_method(:to_s)
)
end
end