The problem appears to manifest when a class inherits from Module, and presumably we are not looking up the string representations correctly.
class A < Module; end; A.new.to_s # => "#<Module:0x6beebab1>" in JRuby, "#<A:0x007f94621be538>" in MRI
In the case above, A.new returns an A object in both cases.
I think I might see the problem here. When the A class is defined, it does get its name (RubyModule.baseName) set properly. However, by the time we reach the to_s, the metaclass for the A instance appears to be a new singleton class. As a result, it ends up following logic for building a singleton class name, which gives us the Module version instead of the A version.
This could either be a problem with how we calculate the singleton name for a module subclass, or potentially as simple as Module.new (getting called for A.new) always creating a new anonymous module.
Note: In my opinion this is not a big issue. Just thought I should let you know.
I think I have a fix...and yeah, not a big issue. Not looking to land any big issues right before release :-)
Fix #497 by using nearest class's name for anon inspect prefix.