Skip to content

Instantly share code, notes, and snippets.

View Serabe's full-sized avatar

Sergio Arbeo Serabe

View GitHub Profile
require 'rbconfig'
require 'java'
require '../src/compilable'
class MyRubyClass
extend Compilable
def helloWorld
puts "Hello from Ruby"
end
require 'rbconfig'
require 'java'
require '../src/compilable'
class MyRubyClass
extend Compilable
def helloWorld
puts "Hello from Ruby"
end
%w{interface java_name package signature}.each do |x|
require File.join(File.dirname(__FILE__), x)
end
module Compilable
def self.extended(a_class)
Class.compilable_classes << a_class if a_class.is_a? Class
end
selection += select_options.delete_if {|k,v| v.blank?}.map do |k,v|
k + '=' + ( ([:integer,:float].include? type_pool.column_for_attribute(k).type) ? v : "'"+v+"'")
end.join(' AND ')
//$ javap -p RubyClass
//Compiled from "inheritance_example.rb"
public class RubyClass extends org.jruby.RubyFixnum{
private static org.jruby.RubyClass __ruby_class__;
static {};
public RubyClass();
}
#$ cat ruby_class.rb
class MyRubyClass
extends_class "MyJavaClass"
end
@JRubyMethod
public IRubyObject native_write_to(ThreadContext context, IRubyObject io, IRubyObject encoding, IRubyObject indentString, IRubyObject options) {
StringWriter sw = new StringWriter();
try {
Transformer t = TransformerFactory.newInstance().newTransformer();
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
t.transform(new DOMSource(this.node), new StreamResult(sw));
} catch (TransformerException te) {
throw context.getRuntime().newRuntimeError("couldn't transform the node back to string");
}
51) Error:
test_write_xml_to(Nokogiri::XML::TestNode):
NativeException: java.lang.IllegalArgumentException: wrong number of arguments
sun/reflect/NativeMethodAccessorImpl.java:-2:in `invoke0'
sun/reflect/NativeMethodAccessorImpl.java:57:in `invoke'
sun/reflect/DelegatingMethodAccessorImpl.java:43:in `invoke'
java/lang/reflect/Method.java:616:in `invoke'
org/jruby/internal/runtime/methods/ReflectedJavaMethod.java:145:in `call'
org/jruby/internal/runtime/methods/DynamicMethod.java:138:in `call'
org/jruby/runtime/callsite/CachingCallSite.java:35:in `call'
@JRubyMethod
public IRubyObject native_write_to(ThreadContext context, IRubyObject io, IRubyObject encoding, IRubyObject indentString, IRubyObject options) {
StringWriter sw = new StringWriter();
try {
Transformer t = TransformerFactory.newInstance().newTransformer();
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
t.transform(new DOMSource(this.node), new StreamResult(sw));
} catch (TransformerException te) {
throw context.getRuntime().newRuntimeError("couldn't transform the node back to string");
}
public void setDocument(IRubyObject doc) {
this.setInstanceVariable("@document", doc);
}