Skip to content

Commit

Permalink
Test that define_singleton_method uses public
Browse files Browse the repository at this point in the history
In CRuby this logic happens to always be public because the target
class (the target object's singleton class) will almost never
match the caller's scope. Pending CRuby confirming that this is
the intended behavior and making it explicit so the caller's frame
is never used for define_singleton_method visibility.
  • Loading branch information
headius authored and eregon committed Mar 28, 2022
1 parent ddb9601 commit 7d630b9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/kernel/define_singleton_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,17 @@ def o.define(name)
o.define(:foo) { raise "not used" }
}.should raise_error(ArgumentError)
end

it "always defines the method with public visibility" do
cls = Class.new
def cls.define(name, &block)
private
define_singleton_method(name, &block)
end

-> {
cls.define(:foo) { :ok }
cls.foo.should == :ok
}.should_not raise_error(NoMethodError)
end
end

0 comments on commit 7d630b9

Please sign in to comment.