A
ara.t.howard
harp:~ > cat a.rb
class Module
def nesting
parent, child = nil
name.split('::').inject(Object){|parent, child| parent.const_get child}
Object == parent ? nil : parent
end
end
class A
class B
class C
class D
end
end
end
end
p A.nesting
p A::B.nesting
p A::B::C.nesting
p A::B::C:.nesting
harp:~ > ruby a.rb
nil
A
A::B
A::B::C
-a
class Module
def nesting
parent, child = nil
name.split('::').inject(Object){|parent, child| parent.const_get child}
Object == parent ? nil : parent
end
end
class A
class B
class C
class D
end
end
end
end
p A.nesting
p A::B.nesting
p A::B::C.nesting
p A::B::C:.nesting
harp:~ > ruby a.rb
nil
A
A::B
A::B::C
-a