Issue #8284 has been updated by marcandre (Marc-Andre Lafortune).


jacknagel (Jack Nagel) wrote:
> As an aside, I see that this is now marked Backport 200, but it would be great if it was backported to 1.9.3 as well.

I don't know if it will be, but in any case there is always `singleton_class.send :public, :define_method` instead or equivalent.

It's a bit more clear, IMO, as using "public_class_method" on a Module is a bit strange... Modules don't really have "class methods".

FWIW, there are no specs in RubySpec about "public_class_method" on a Module.
----------------------------------------
Backport #8284: Expected behavior of Module#public_class_method
https://bugs.ruby-lang.org/issues/8284#change-38720

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/