21. Executable Class Definition
class Message
if RUBY_PLATFORM =~ /java/i
def hello
puts quot;Hello From JRubyquot;
end
end
end
http://localhost:4567/code/env.rb
21
28. JI: Java Extensions
module java::util::Map
include Enumerable
def each(&block)
entrySet.each { |pair| block.call([pair.key, pair.value]) }
end
def [](key)
get(key)
end
def []=(key,val)
put(key,val)
val
end
end
28
29. JI: Open Java Classes
class Java::JavaLang::Integer
def even?
int_value % 2 == 0
end
def odd?
int_value % 2 == 1
end
end
http://localhost:4567/code/ji/integer.rb
29
30. JI: Interface Conversion
package java.util.concurrent;
public class Executors {
// ...
public static Callable callable(Runnable r) {
// ...
}
}
30
31. JI: Interface Conversion
class SimpleRubyObject
def run
puts quot;hiquot;
end
end
callable = Executors.callable(SimpleRubyObject.new)
callable.call
http://localhost:4567/code/ji/if_conversion.rb
31
38. webmate
require 'rubygems'
require 'sinatra'
get '/*' do
file, line = request.path_info.split(/:/)
local_file = File.join(Dir.pwd, file)
if (File.exists?(local_file))
redirect quot;txmt://open/?url=file://#{local_file}&line=#{line}quot;
else
not_found
end
end
http://localhost:4567/code/webmate.rb
38
41. RSpec Testing Java
describe quot;An emptyquot;, HashMap do
before :each do
@hash_map = HashMap.new
end
it quot;should be able to add an entry to itquot; do
@hash_map.put quot;fooquot;, quot;barquot;
@hash_map.get(quot;fooquot;).should == quot;barquot;
end
end
JTestr Provides Ant and Maven integration
http://jtestr.codehaus.org
http://localhost:4567/code/hashmap_spec.rb
41