From: "list. rb" Date: 2007-07-01T13:09:39+09:00 Subject: Re: Ruby vs Java (this,self/main) ------=_Part_84370_7171900.1183262969451 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Awesome Charles. I had to make one change to your suggestion: class MySubscriber < com.feed.service.PFSubscriber def newEvent(event) puts event end end For some reason, the other syntax was throwing an error. Thanks a million for the help On 6/30/07, Charles Oliver Nutter wrote: > > list. rb wrote: > > ###### Ruby Version: > > df = Java::Establisher.connect(user_pass_etc, "FeedSubscriberPublisher") > > pfconn = Java::FSStarter.startConn(df, self) > > pfconn.start > > puts "Subscribing to Feed events" > > pfconn.subscribe("PFEventFeedUpdate") > > def newEvent(event) > > puts event > > end > > > > > > The Ruby version breaks when providing 'self' as the 'this' equivalent > when > > connecting(line two in the ruby script, here it is in IRB): > > I think the problem here is that the "self" you're passing doesn't > implement whatever interfaces you need on the Java side. > > Because we have to match the static types Java's looking for, simply > implementing the method isn't enough; you need to give JRuby a chance to > actually create a real Java type: > > class MySubscriber > include Java::PFSubscriber > > def newEvent(event) > puts event > end > end > df = Java::Establisher.connect(user_pass_etc, "FeedSubscriberPublisher") > pfconn = Java::FSStarter.startConn(df, MySubscriber.new) > pfconn.start > puts "Subscribing to Feed events" > pfconn.subscribe("PFEventFeedUpdate") > > There's also some shortcut syntaxes that are somewhat experimental, but > make this process a little easier: > > pfconn = Java::FSStarter.startConn(df, PFSubscriber.impl {|method, > *args| puts args[0]}) > > - Charlie > > ------=_Part_84370_7171900.1183262969451--