-
-
Save copiousfreetime/1250973 to your computer and use it in GitHub Desktop.
ruby class inheriting from a java class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'java' | |
require 'jruby/core_ext' | |
# brew install hadoop | |
HADOOP_ROOT = "/usr/local/Cellar/hadoop/0.21.0/libexec/" | |
Dir.glob( File.join( HADOOP_ROOT, "**/*.jar" ) ).each do |jar| | |
require jar | |
end | |
# http://hadoop.apache.org/mapreduce/docs/r0.21.0/api/org/apache/hadoop/mapreduce/Mapper.html | |
# org.apache.hadoop.mapreduce Class Mapper<KEYIN,VALUEIN,KEYOUT,VALUEOUT> | |
Mapper = org.apache.hadoop.mapreduce.Mapper | |
class TestA < Mapper | |
end | |
puts "Ruby TestA class : #{TestA.name}" | |
puts "Test A Ancestors: #{TestA.ancestors.join(", ")}" | |
java_class = TestA.become_java! | |
if java_class.nil? then | |
puts "become_java! returned nil" | |
puts "TestA name = #{TestA.name}" | |
else | |
puts java_class.interfaces.each { |i| puts i } | |
end | |
__END__ | |
% ruby ./j.rb | |
Ruby TestA class : TestA | |
Test A Ancestors: TestA, Java::OrgApacheHadoopMapreduce::Mapper, Java::JavaLang::Object, ConcreteJavaProxy, JavaProxy, JavaProxyMethods, Object, Kernel | |
become_java! returned nil | |
TestA name = TestA |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment