R
RichardOnRails
Hi,
I wrote a method to display a class' "parentage" based on an idea in
"Ruby Cookbook", sec. 10.1:
def parents(obj)
( (obj.superclass ? parents(obj.superclass) : []) << obj). reverse
end
I displayed Class' parent-class hierarchy with:
Class.superclass.inspect => Module
Module.superclass.inspect => Object
Object.superclass.inspect => nil
Then I tested the automatic generation of that hierarchy as follows:
parents(Class).inspect => [Class, Object, Module]
Expected: [Class, Module, Object]
I tried display intermediate values during the recursion, but I
couldn't see where I'm going wrong. Any ideas?
Thanks in advance,
Richard
I wrote a method to display a class' "parentage" based on an idea in
"Ruby Cookbook", sec. 10.1:
def parents(obj)
( (obj.superclass ? parents(obj.superclass) : []) << obj). reverse
end
I displayed Class' parent-class hierarchy with:
Class.superclass.inspect => Module
Module.superclass.inspect => Object
Object.superclass.inspect => nil
Then I tested the automatic generation of that hierarchy as follows:
parents(Class).inspect => [Class, Object, Module]
Expected: [Class, Module, Object]
I tried display intermediate values during the recursion, but I
couldn't see where I'm going wrong. Any ideas?
Thanks in advance,
Richard