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

Discussion in 'Ruby' started by x1, Dec 19, 2006.

  1. x1

    x1 Guest

    # 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.
     
    x1, Dec 19, 2006
    #1
    1. Advertising

  2. x1

    Eric Hodel Guest

    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!
     
    Eric Hodel, Dec 19, 2006
    #2
    1. Advertising

  3. x1

    x1 Guest

    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!
    >
    >
    >
     
    x1, Dec 19, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Miles Keaton
    Replies:
    3
    Views:
    197
    Miles Keaton
    Mar 30, 2005
  2. Kirk Haines

    More DRb; SSL & DRB & errors

    Kirk Haines, Jul 1, 2005, in forum: Ruby
    Replies:
    0
    Views:
    145
    Kirk Haines
    Jul 1, 2005
  3. J. Wook
    Replies:
    16
    Views:
    300
    Robert Klemme
    May 16, 2007
  4. Charles Oliver Nutter

    [JRuby] JRuby perf questions answered

    Charles Oliver Nutter, Oct 31, 2007, in forum: Ruby
    Replies:
    7
    Views:
    195
    Kevin Williams
    Nov 1, 2007
  5. Ittay Dror
    Replies:
    1
    Views:
    150
    Ittay Dror
    Oct 21, 2008
Loading...

Share This Page