From: Sean O'Halpin Date: 2007-04-01T00:35:33+09:00 Subject: Re: Find the fully qualified name of a class from a string On 3/31/07, Brian Candler wrote: > On Sat, Mar 31, 2007 at 05:54:42AM +0900, Nasir Khan wrote: > > Say you have a class definition in a string - > > > > str = < > module A > > class B > > def b > > puts "hello" > > end > > end > > end > > EOF > > > > What is the easiest way to find out the fully qualified name of the class > > there, namely "A::B" > > Interesting. I thought that in general you couldn't: > > m = Module.new > Foo = m > Bar = m > module m > # what's the *name* of the module we are in now?? > end > > But actually Ruby rejects that, so you must say 'module Foo' or 'module Bar' > I think this illustrates your point: m = Module.new do attr_accessor :name end B = Class.new do include m end p B.ancestors # [B, #, Object, Kernel] Regards, Sean