Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > DRb, Ruby & JRuby - Questions & Issues / dynamic method calls

Reply
Thread Tools

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

 
 
x1
Guest
Posts: n/a
 
      12-19-2006
# I overview after these examples to ease the pain

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

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

# This works:
@@connection.send("getForeignListing").send("getLi sting",
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).ge tStreet

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.

 
Reply With Quote
 
 
 
 
Eric Hodel
Guest
Posts: n/a
 
      12-19-2006
On Dec 18, 2006, at 19:43, x1 wrote:

> ------------------------------------------------
> # 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])

--
Eric Hodel - - http://blog.segment7.net

I LIT YOUR GEM ON FIRE!


 
Reply With Quote
 
 
 
 
x1
Guest
Posts: n/a
 
      12-19-2006
Thank you Eric

On 12/19/06, Eric Hodel <> wrote:
> On Dec 18, 2006, at 19:43, x1 wrote:
>
> > ------------------------------------------------
> > # 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])
>
> --
> Eric Hodel - - http://blog.segment7.net
>
> I LIT YOUR GEM ON FIRE!
>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JRubyHub.com: The hub to all JRuby and JRuby on Rails (JRoR)resources... Slim Baltagi Java 0 12-15-2007 07:26 PM
[ANN] [JRuby] Fast Debugger for JRuby Martin Krauskopf Ruby 0 11-11-2007 10:47 PM
[JRuby] JRuby perf questions answered Charles Oliver Nutter Ruby 7 11-01-2007 05:11 AM
Any JRUBY programmers out there? Problems specifying RUBYLIB with jruby. Ronald Fischer Ruby 2 05-16-2007 09:34 PM
JRuby: How does one keep Java objects as Java objects so they can be used in method calls? Steve Drach Ruby 3 06-19-2004 11:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57