# DRb, Ruby & JRuby - Questions & Issues / dynamic method call

**URL:** <https://www.ruby-forum.com/t/drb-ruby-jruby-questions-issues-dynamic-method-call/79972>\
**Category:** Ruby\
**Created:** [December 20, 2006, 7:20pm UTC](https://www.ruby-forum.com/t/drb-ruby-jruby-questions-issues-dynamic-method-call/79972 "2006-12-20T19:20:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![d0t1q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@d0t1q](https://www.ruby-forum.com/u/d0t1q)\
**Post date:** [December 20, 2006, 7:20pm UTC](https://www.ruby-forum.com/t/drb-ruby-jruby-questions-issues-dynamic-method-call/79972/1 "2006-12-20T19:20:45Z")

</div>

# 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©  
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.

---

<div class="post-metadata">

**Author:** ![d0t1q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@d0t1q](https://www.ruby-forum.com/u/d0t1q)\
**Post date:** [December 20, 2006, 7:53pm UTC](https://www.ruby-forum.com/t/drb-ruby-jruby-questions-issues-dynamic-method-call/79972/2 "2006-12-20T19:53:18Z")

</div>

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 H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)

I LIT YOUR GEM ON FIRE!
