Project

General

Profile

Bug #19749

Updated by Eregon (Benoit Daloze) over 1 year ago

This issue is a special case of https://bugs.ruby-lang.org/issues/19745: 

 Should dynamically added private methods via `.singleton_class.send(:define_method,...` at the top-level be accessible publicly? 

 See the following example: 

 ```ruby 
 def bar; end 

 foo = Object.new 
 foo.singleton_class.define_method(:bar, foo.singleton_class.send(:define_method, :bar, method(:bar)) 

 foo.bar # No error. 
 ``` 

 The script above runs fine on latest Ruby 3.3. Is this correct to ignore the fact that the visibility in the caller context is the default top-level private visibility? 

 This came up during a TruffleRuby investigation (https://github.com/oracle/truffleruby/issues/3134) where the result for the same script is: `private method 'bar' called for #<Object:0xc8> (NoMethodError)` 

Back