Sha256: 8aa5b50453f996f9179c8335d6c86835be389e4f1032253d5c78529415931104

Contents?: true

Size: 788 Bytes

Versions: 4

Compression:

Stored size: 788 Bytes

Contents

module JrubyCoercion
  module Coercable

    def self.included(klass)
      unless klass.method_defined?(:jruby_default_to_java)
        klass.class_eval do 
          alias_method :jruby_default_to_java, :to_java

          def to_java(java_type = nil)
            converter = ::JrubyCoercion::RubyToJava::Registry.registry_converts_class_and_to?(self.class, java_type)

            if converter
              return converter.call(self)
            else
              jruby_default_to_java(java_type)
            end
          end


          def coerce_to?(java_type)
            return ::JrubyCoercion::RubyToJava::Registry.registry_converts_class_and_to?(self.class, java_type)
          end
          alias_method :coerced_to?, :coerce_to?

        end
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jruby_coercion-0.0.7-java lib/jruby_coercion/coercable.rb
jruby_coercion-0.0.6-java lib/jruby_coercion/coercable.rb
jruby_coercion-0.0.5-java lib/jruby_coercion/coercable.rb
jruby_coercion-0.0.4-java lib/jruby_coercion/coercable.rb