Class: Class

Inherits:
Object
  • Object
show all
Defined in:
lib/gherkin/native/ikvm.rb,
lib/gherkin/native/java.rb,
lib/gherkin/native/null.rb

Instance Method Summary collapse

Instance Method Details

#implements(java_class_name) ⇒ Object



3
4
5
6
7
8
# File 'lib/gherkin/native/ikvm.rb', line 3

def implements(java_class_name)
  m = java_class_name.split('.').inject(Object) do |mod, name|
    mod = mod.const_get(name)
  end
  include m
end

#native_impl(lib) ⇒ Object

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.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/gherkin/native/ikvm.rb', line 14

def native_impl(lib)
  begin
    load_assembly(lib)
  rescue LoadError => e
    e.message << "\nTry this: SET MONO_PATH=#{File.expand_path(File.dirname(__FILE__) + '/../..')} (or export MONO_PATH=...)"
    raise e
  end

  class << self
    def ikvmify(arg)
      if Array === arg
        arg.map{|a| ikvmify(a)}
      else
        case(arg)
        when Regexp
          Object.const_get('java').const_get('util').const_get('regex').const_get('Pattern').compile(arg.source)
        else
          arg
        end
      end
    end

    def new(*args)
      ikvm_class.new(*ikvmify(args))
    end

    def ===(object)
      super || object.java_kind_of?(java_class)
    end

    def ikvm_class
      names = self.name.split('::')
      namespace = Object
      names[0..-2].each do |module_name|
        namespace = namespace.const_get(module_name.downcase)
      end

      namespace.const_get(names[-1])
    end
  end
end