Module: RAW::RjbAdapter

Defined in:
lib/rjb_adapter.rb

Class Method Summary collapse

Class Method Details

.extract_class_name(str) ⇒ Object

Here we extract the class name from a given String e.g. str = “java.lang.String” -> class_name = “String”



34
35
36
# File 'lib/rjb_adapter.rb', line 34

def extract_class_name(str)
  class_name = str.split(".").last
end

.import_class(name) ⇒ Object

Wrapper for import_class from JRuby If we’re on JRuby we use normal import_class Otherwise we use Rjb::import



25
26
27
28
29
30
31
# File 'lib/rjb_adapter.rb', line 25

def import_class(name)
  if is_jruby?
    return import_using_jruby(name)
  else
    return Rjb::import(name)
  end
end

.is_jruby?Boolean

We test if the RUBY_PLATFORM is ‘java’ If true we will use JRuby If false we will use Rjb gem

Returns:

  • (Boolean)


18
19
20
# File 'lib/rjb_adapter.rb', line 18

def is_jruby?
  return Gem.ruby =~ /jruby/
end

.load(files = [], args = []) ⇒ Object

Here we load the files we need When in JRuby, we do a require for each jar in files argument Otherwise we use Rjb::load to load all jars from a path build from files parameter



40
41
42
43
44
45
46
# File 'lib/rjb_adapter.rb', line 40

def load(files=[], args=[])
  if is_jruby?
    files.each {|jar| require jar }
  else
    Rjb::load(files.join(File::PATH_SEPARATOR), [])
  end
end