Class: Module

Inherits:
Object show all
Defined in:
core/src/main/ruby/jruby/java/core_ext/module.rb

Overview

Extensions to the standard Module package.

Class Method Summary (collapse)

Class Method Details

+ (Object) const_missing(constant)



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
# File 'core/src/main/ruby/jruby/java/core_ext/module.rb', line 21

def self.const_missing(constant)
  real_name = @java_aliases[constant] || constant

  java_class = nil
  last_error = nil

  @included_packages.each do |package|
      begin
        java_class = JavaUtilities.get_java_class("#{package}.#{real_name}")
      rescue NameError
        # we only rescue NameError, since other errors should bubble out
        last_error = $!
      end
      break if java_class
  end

  if java_class
    return JavaUtilities.create_proxy_class(constant, java_class, self)
  else
    # try to chain to super's const_missing
    begin
      return super
    rescue NameError
      # super didn't find anything either, raise our Java error
      raise NameError.new("#{constant} not found in packages #{@included_packages.join(', ')}; last error: #{last_error.message}")
    end
  end
end