Re: Ruby vs Java (this,self/main)
- From: Charles Oliver Nutter <charles.nutter@xxxxxxx>
- Date: Sun, 1 Jul 2007 04:03:52 +0900
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
.
- Prev by Date: Re: de-camelcase a filename
- Next by Date: ANN: Sequel 0.1.7 Released
- Previous by thread: Re: de-camelcase a filename
- Next by thread: ANN: Sequel 0.1.7 Released
- Index(es):
Relevant Pages
|