The name of a module nested in an anonymous module depends on how it was created
If a module is nested under an anonymous module, the nested modules name will depend on how the module is created. See below:
1.9.3p125 :001 > m = Module.new
1.9.3p125 :002 > n = Module.new
1.9.3p125 :003 > m::N = n
1.9.3p125 :004 > m.name
1.9.3p125 :005 > n.name
1.9.3p125 :006 > m.constants
1.9.3p125 :007 > module m::O
1.9.3p125 :008?> end
1.9.3p125 :009 > m.constants
=> [:N, :O]
1.9.3p125 :010 > m::N.name
1.9.3p125 :011 > m::O.name
1.9.3p125 :012 > m.const_get(:N).name
1.9.3p125 :013 > m.const_get(:O).name
1.9.3p125 :014 > M = m
1.9.3p125 :015 > m::N.name
1.9.3p125 :016 > m::O.name
Updated by brixen (Brian Shirai) over 8 years ago
There is a case not given above where it may make sense to give the class/module a name based on #inspect output of the containing class. This case is when the containing class is a singleton class:
1.9.3p125 :001 > obj = Object.new
1.9.3p125 :002 > class << obj
1.9.3p125 :003?> class B
1.9.3p125 :004?> end
1.9.3p125 :005?> end
1.9.3p125 :006 > obj.singleton_class.name
1.9.3p125 :007 > obj.singleton_class.const_get(:B).name
1.9.3p125 :008 >
However, note that the singleton class itself has no name, so giving the nested class/module a name like "#Class:0x00000101142948::B" seems wrong.
Updated by nobu (Nobuyoshi Nakada) almost 8 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r36574.
Brian, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- variable.c: store anonymous class path in tmp_classpath but not in classpath. [ruby-core:42865][Bug #6078]