Project

General

Profile

Actions

Bug #19749

open

Confirm correct behaviour when attaching private method with `#define_method`

Added by itarato (Peter Arato) 11 months ago. Updated 7 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:114038]

Description

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:

def bar; end

foo = Object.new
foo.singleton_class.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)

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like1Like0Like0Like0Like0Like0