This file contains hidden or 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 'rbconfig' | |
| require 'java' | |
| require '../src/compilable' | |
| class MyRubyClass | |
| extend Compilable | |
| def helloWorld | |
| puts "Hello from Ruby" | |
| end |
This file contains hidden or 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 'rbconfig' | |
| require 'java' | |
| require '../src/compilable' | |
| class MyRubyClass | |
| extend Compilable | |
| def helloWorld | |
| puts "Hello from Ruby" | |
| end |
This file contains hidden or 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
| %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 |
This file contains hidden or 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
| 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 ') |
This file contains hidden or 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
| //$ 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(); | |
| } |
This file contains hidden or 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
| #$ cat ruby_class.rb | |
| class MyRubyClass | |
| extends_class "MyJavaClass" | |
| end |
This file contains hidden or 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
| @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"); | |
| } |
This file contains hidden or 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
| 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' |
This file contains hidden or 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
| @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"); | |
| } |
This file contains hidden or 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
| public void setDocument(IRubyObject doc) { | |
| this.setInstanceVariable("@document", doc); | |
| } |