From: "jacknagel (Jack Nagel)" Date: 2013-04-19T04:42:57+09:00 Subject: [ruby-core:54442] [Backport 200 - Backport #8284] Expected behavior of Module#public_class_method Issue #8284 has been updated by jacknagel (Jack Nagel). It does: irb(main):001:0> RUBY_DESCRIPTION => "ruby 2.1.0dev (2013-04-19 trunk 40359) [i386-darwin10.8.0]" irb(main):002:0> Object.define_method NoMethodError: private method `define_method' called for Object:Class from (irb):2 from /Users/jacknagel/.rubies/ruby-2.1.0-dev/bin/irb:12:in `
' irb(main):003:0> module Foo; public_class_method :define_method; end => Foo irb(main):004:0> Object.define_method NoMethodError: private method `define_method' called for Object:Class from (irb):4 from /Users/jacknagel/.rubies/ruby-2.1.0-dev/bin/irb:12:in `
' ---------------------------------------- Backport #8284: Expected behavior of Module#public_class_method https://bugs.ruby-lang.org/issues/8284#change-38718 Author: jacknagel (Jack Nagel) Status: Assigned Priority: Normal Assignee: nagachika (Tomoyuki Chikanaga) Category: Target version: It was pointed out by Myron Marston (here: https://gist.github.com/myronmarston/5401829) that calling public_class_method on an anonymous module makes the named method public on Object, etc. Object.define_method => NoMethodError Module.new.public_class_method(:define_method) Object.define_method => ArgumentError Also of note, the same is not true when calling it on a class: Object.define_method => NoMethodError Class.new.public_class_method(:define_method) Object.define_method => NoMethodError which seems inconsistent given: Module.new.singleton_class.ancestors => [Module, Object, Kernel, BasicObject] Class.new.singleton_class.ancestors => [Class, Module, Object, Kernel, BasicObject] Is this a bug or expected behavior? If the latter, what is the correct explanation? -- http://bugs.ruby-lang.org/