Tyler Pirtle
4/27/2005 1:45:00 AM
I'm not even sure if this would be possible but I think I need some
help. In the spirit of the method_missing hall of fame, I want to be
able to do..sort of a nested method_missing.
how can i get at
Instance.bogus_member1.bogus_member2
bogus_member2 through the class of Instance?
Or better yet, suppose bogus_member1 returned an object, how could I
get at bogus_member2 through the class of the object of bogus_member1?
I've tried just using method_missing statements in 2 different
classes, but Ruby seems to want to perform the last method first - and
because bogus_member1 doesn't exist its trying to call something from
NilClass.
Ideally, what will happen is that bogus_member1 will be an object that
will be instantiated based on its own criteria - for example, suppose
every day of school you had a new teacher
School.MrSmith.homework
but the next day
School.MrsJones.homework
MrSmith & MrsJones are objects that get instantiated as Teachers based
on their criteria -
class School
def method_missing(*args)
...
Teachers.new(args[0])
end
What i'd like to do is at that same line...
Teacher.new(args[0]).send(args[1..-1]))
But it seems as if Ruby is going in the other direction.(end to start)
What can I do?