class method call via the singleton or not

T

Trans

Hi--

Little bit of conundrum. I have a variables that tracks information
about methods. So it needs to work within the context of the class
hierarchy. At the same time I need to access that information from the
instance level. I worked it out with one exception --singleton, b/c I
do something like:

class Foo

def self.dolist( name )
list = nil
ancestors.each do |a|
if d = a.instance_variable_get("@dolist")
list = d[name.to_sym]
break if list
end
end
list
end

def foo
self.class.dolist()
end

end

This works unless there is singleton in the hierarchy that has @dolist
defined. But I don't want to call directly on the singleton in foo in
case the singleton doesn't exist --I think that would be an exceedingly
inefficient. Is there another way?

Thanks,
T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top