DRb, Ruby & JRuby - Questions & Issues / dynamic method calls

X

x1

# I overview after these examples to ease the pain :)

@@connection = Java::Connect(usr,pass)

# This works:
@@connection.getForeignListing.getListing(1441).getStreet #=> 123 Candy Ln.

# This works:
@@connection.send("getForeignListing").send("getListing",
1441).send("getStreet") #=> 123 Candy Ln.

# This works:
def test(a,b,c,d)
return @@connection.send(a).send(b,c).send(d)
end
test("getForeignListing", "getListing", 1441, "getStreet")

------------------------------------------------
# Does not work:
def test(a,b,c)
return @@connection.send(a).send(b).send(c)
end
test("getForeignListing", ["getListing", 1441], "getStreet")

test.rb:4:in `send': ["getListing", 5053500] is not a symbol (TypeError)
------------------------------------------------

In summary, I've managed to hook the working versions above within a
class for a DRb server.

The ultimate goal, is to create a generic DRb method that client input
into into method-syntax that the connection can interpret.

For example, as mentioned above, this works:
@@connection.getForeignListing.getListing(1441).getStreet

I'd like to create a method in the DRb server that could accept something like:
java_call = "getForeignListing.getListing(1441).getStreet"
@@connection.send(java_call)

This would allow me to dynamically manage the java methods via DRb.

Thanks so much for your input.
 
E

Eric Hodel

------------------------------------------------
# Does not work:
def test(a,b,c)
return @@connection.send(a).send(b).send(c)
end
test("getForeignListing", ["getListing", 1441], "getStreet")

test.rb:4:in `send': ["getListing", 5053500] is not a symbol
(TypeError)

This won't ever work.

$ ri Object#send
------------------------------------------------------------ Object#send
obj.send(symbol [, args...]) => obj
obj.__send__(symbol [, args...]) => obj
------------------------------------------------------------------------
Invokes the method identified by symbol, passing it any arguments
specified. You can use __send__ if the name send clashes with an
existing method in obj.

You want:

send(*['getListing', 5053500])
 
X

x1

Thank you Eric

------------------------------------------------
# Does not work:
def test(a,b,c)
return @@connection.send(a).send(b).send(c)
end
test("getForeignListing", ["getListing", 1441], "getStreet")

test.rb:4:in `send': ["getListing", 5053500] is not a symbol
(TypeError)

This won't ever work.

$ ri Object#send
------------------------------------------------------------ Object#send
obj.send(symbol [, args...]) => obj
obj.__send__(symbol [, args...]) => obj
------------------------------------------------------------------------
Invokes the method identified by symbol, passing it any arguments
specified. You can use __send__ if the name send clashes with an
existing method in obj.

You want:

send(*['getListing', 5053500])
 

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,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top