Project

General

Profile

Actions

Bug #9141

closed

define_singleton_method creates private method

Added by Soilent (Konstantin x) about 11 years ago. Updated almost 11 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.0dev (2013-09-22 trunk 43011) [x86_64-darwin12.5.0]
[ruby-core:58497]

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 2 (0 open2 closed)

Related to Backport21 - Backport #9296: please backport r44380 (visibility of methods defined by define_method)Closednaruse (Yui NARUSE)12/25/2013Actions
Is duplicate of Ruby master - Bug #9005: object.send(:define_method, ...){...} creates private methodClosednobu (Nobuyoshi Nakada)10/09/2013Actions

Updated by jeremyevans0 (Jeremy Evans) about 11 years ago

This is probably related to #9005.

Actions #2

Updated by nobu (Nobuyoshi Nakada) almost 11 years 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. [ruby-core:57747] [Bug #9005]
    [ruby-core:58497] [Bug #9141]
  • vm.c (rb_vm_cref_in_context): return ruby level cref if self is
    same.

Updated by nobu (Nobuyoshi Nakada) almost 11 years 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
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0