Bug #9141

define_singleton_method creates private method

Added by Konstantin H over 1 year ago. Updated over 1 year ago.

[ruby-core:58497]
Status:Closed
Priority:Normal
Assignee:-
ruby -v:ruby 2.1.0dev (2013-09-22 trunk 43011) [x86_64-darwin12.5.0] Backport:1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1.0: REQUIRED

Description

Hello,
I stumbled upon the following problem:

irb(main):001:0> guy = "Bob"
=> "Bob"
irb(main):002:0> guy.define_singleton_method(:hello) { "#{self}: Hello there!" }
=> :hello
irb(main):003:0> guy.hello
NoMethodError: private method `hello' called for "Bob":String
from (irb):3


Related issues

Related to Backport21 - Backport #9296: please backport r44380 (visibility of methods defined by define_method) Closed 12/25/2013
Duplicates Ruby trunk - Bug #9005: object.send(:define_method, ...){...} creates private method Closed 10/09/2013

Associated revisions

Revision 44380
Added by Nobuyoshi Nakada over 1 year ago

proc.c: make method by define_method public

  • proc.c (rb_mod_define_method): consider visibility only if self in the caller is same as the receiver, otherwise make public as well as old behavior. [Bug #9005] [Bug #9141]
  • vm.c (rb_vm_cref_in_context): return ruby level cref if self is same.

Revision 44380
Added by Nobuyoshi Nakada over 1 year ago

proc.c: make method by define_method public

  • proc.c (rb_mod_define_method): consider visibility only if self in the caller is same as the receiver, otherwise make public as well as old behavior. [Bug #9005] [Bug #9141]
  • vm.c (rb_vm_cref_in_context): return ruby level cref if self is same.

History

#1 Updated by Jeremy Evans over 1 year ago

This is probably related to #9005.

#2 Updated by Nobuyoshi Nakada over 1 year ago

  • Status changed from Open to Closed

This issue was solved with changeset r44380.
Jeremy, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


proc.c: make method by define_method public

  • proc.c (rb_mod_define_method): consider visibility only if self in the caller is same as the receiver, otherwise make public as well as old behavior. [Bug #9005] [Bug #9141]
  • vm.c (rb_vm_cref_in_context): return ruby level cref if self is same.

#3 Updated by Nobuyoshi Nakada over 1 year ago

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1.0: REQUIRED

Also available in: Atom PDF