From: Nobuyoshi Nakada Date: 2011-12-26T06:47:44+09:00 Subject: [ruby-core:41809] [Archive91 - Backport #5807][Rejected] "define_method" not consistent with "def" Issue #5807 has been updated by Nobuyoshi Nakada. Status changed from Open to Rejected =begin These two are different things. def foo1 puts "foo1 called" end class << self define_method(:foo2) do puts "foo2 called" end end While (({foo1})) is a private instance method of (({Object})), (({foo2})) is a private singleton method of (({main})). =end ---------------------------------------- Backport #5807: "define_method" not consistent with "def" https://bugs.ruby-lang.org/issues/5807 Author: Silvio Cordeiro Status: Rejected Priority: Normal Assignee: Category: Target version: =begin Under at least Ruby 1.8.7 and 1.9.1, the following definitions are not equivalent: def foo1 puts "foo1 called" end class << self define_method(:foo2) do puts "foo2 called" end end While ((|foo1|)) always works, ((|foo2|)) is considered *undefined* in some contexts. For example, this method works: (({ def call_foos foo1 foo2 end })) but ((|Bad.new|)) below would not work, failing because ((|foo2|)) is undefined: (({ class Bad def initialize foo1 foo2 end end })) See attached file with an example code that is even stranger than this. =end -- http://redmine.ruby-lang.org