Sean O'Halpin
3/31/2007 3:36:00 PM
On 3/31/07, Brian Candler <B.Candler@pobox.com> wrote:
> On Sat, Mar 31, 2007 at 05:54:42AM +0900, Nasir Khan wrote:
> > Say you have a class definition in a string -
> >
> > str = <<EOF
> > 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, #<Module:0xb7c3bc2c>, Object, Kernel]
Regards,
Sean