Sha256: aa74e531b17a4d59ef52fbd85f1ecb3551ede49a2926575a6be80cd0f54c3ebf

Contents?: true

Size: 693 Bytes

Versions: 4

Compression:

Stored size: 693 Bytes

Contents

class Class
  # Causes a Java class to be instantiated instead of the Ruby class when 
  # running on JRuby. This is used to test both pure Java and pure Ruby classes 
  # from the same Ruby based test suite. The Java Class must have a package name
  # that corresponds with the Ruby class.
  def java_impl(jar)
    if defined?(JRUBY_VERSION)
      require jar
      class << self
        define_method(:new) do |*args|
          names = self.name.split('::')
          package = Java
          names[0..-2].each do |module_name|
            package = package.__send__(module_name.downcase)
          end
          package.__send__(names[-1]).new(*args)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gherkin-1.0.9 lib/gherkin/java_impl.rb
gherkin-1.0.9-i386-mswin32 lib/gherkin/java_impl.rb
gherkin-1.0.9-i386-mingw32 lib/gherkin/java_impl.rb
gherkin-1.0.9-java lib/gherkin/java_impl.rb