Hi, I'm trying to use respond_to on a class for the purpose of getting
DRb to work with
method_missing. This is basically what i am doing. The situation is
that i'm not getting
the proper execution of methods if i use respond_to in this manner with
method_missing.
If i don't have a return true for @childrenArray in the respond_to then
things seem to work,
otherwise it seems to call the method_missing but the return value from
the @childArray send
doesn't seem to make it.. to_ary is being called , i'm trying to call
Foo.flatten.uniq
Any Suggestions?
class Foo
alias_method :old_respond_to? :respond_to?
def respond_to?(msg_id)
return true if @childrenArray.respond_to?(msg_id)
return true if self.old_respond_to?(msg_id)
false
end
def method_missing(*args)
if @childrenArray.respond_to(args[0])
return @childrenArray.send(*args)
else
raise NameError, "#{args.join(',')}"
end
end
end
Let ruby do more work for you.
Would Delegator or Forwardable be of assistance?
class Foo
# no need to alias respond_to?, it is available from the superclass.
def respond_to?(meth)
return true if @childrenArray.respond_to? meth
return super
end
# I always break method apart, because its always there
# Don't forget the block, unless you don't need it
# No need to check for respond_to? Ruby will DTRT
def method_missing(meth, *args, &block)
return @childrenArray.send(meth, *args, &block)
end
end
···
On 07 Jun 2005, at 08:05, curtis.schofield@gmail.com wrote:
Hi, I'm trying to use respond_to on a class for the purpose of getting DRb to work with method_missing. This is basically what i am doing. The situation is that i'm not getting the proper execution of methods if i use respond_to in this manner with method_missing.
If i don't have a return true for @childrenArray in the respond_to then things seem to work, otherwise it seems to call the method_missing but the return value from the @childArray send doesn't seem to make it.. to_ary is being called , i'm trying to call Foo.flatten.uniq
Any Suggestions?
--
Eric Hodel - drbrain@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
Let ruby do more work for you.
Would Delegator or Forwardable be of assistance?
I was using Delegator previously but it had a bunch of wierdness and
i had to write extra code to handle switching the object that would be
delegated against. It seemed like extra work. I'll see if super helps
and if not i'll check out Forwardable or go back to trying
SimpleDelegate
Thanks for the tip with super.. i should have realized. =D
# I always break method apart, because its always there
me to, but for brevity in the example.... ;p
Let ruby do more work for you.
Would Delegator or Forwardable be of assistance?
I was using Delegator previously but it had a bunch of wierdness and
i had to write extra code to handle switching the object that would be
delegated against. It seemed like extra work. I'll see if super helps
and if not i'll check out Forwardable or go back to trying
SimpleDelegate
Thanks for the tip with super.. i should have realized. =D
# I always break method apart, because its always there
me to, but for brevity in the example.... ;p
Cheers,
Thanks again Eric!
Curtis
i'll check out Forwardable or go back to trying
SimpleDelegate
Hmm for some reason the respond_to affects how the method_missing
seems to work, I'll have to use the suggested.
Argh.. Delegator doesn't help either...
I'll have to look into this carefully