Project

General

Profile

Actions

Bug #19745

closed

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

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

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:114029]

Description

Should dynamically added private methods be accessible publicly?

See the following example?

private def bar; end

foo = Object.new
foo.define_singleton_method(:bar, method(:bar))

foo.bar # No error.

The script above runs fine on latest Ruby HEAD. Is this correct to ignore the fact that the added method (method(:bar)) is private?

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
Like0Like0Like0