DRb Method_mising respond_to?

  • Thread starter curtis.schofield
  • Start date
C

curtis.schofield

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 :eek:ld_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
 
E

Eric Hodel

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?

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
 
C

curtis.schofield

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
 
C

curtis.schofield

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
 
C

curtis.schofield

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.
 
C

curtis.schofield

Argh.. Delegator doesn't help either...

I'll have to look into this carefully
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top