From: Charles Oliver Nutter Date: 2007-07-01T04:03:52+09:00 Subject: Re: Ruby vs Java (this,self/main) 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