Class: JavaPackage
- Inherits:
-
Object
show all
- Defined in:
- lib/rjb/extension.rb
Constant Summary
collapse
- @@cache =
{}
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(pack_name, parent_pack = nil) ⇒ JavaPackage
Returns a new instance of JavaPackage.
82
83
84
85
86
|
# File 'lib/rjb/extension.rb', line 82
def initialize(pack_name, parent_pack = nil)
@pack_name = pack_name
@parent_pack = parent_pack
@cache = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
88
89
90
91
|
# File 'lib/rjb/extension.rb', line 88
def method_missing(m, *args)
@cache[m] ||= create_package_or_class(m)
end
|
Class Method Details
.new(pack_name, parent_pack = nil) ⇒ Object
115
116
117
|
# File 'lib/rjb/extension.rb', line 115
def self.new(pack_name, parent_pack = nil)
@@cache[pack_name] ||= super
end
|
Instance Method Details
#class?(a) ⇒ Boolean
109
110
111
112
|
# File 'lib/rjb/extension.rb', line 109
def class?(a)
first_letter = a[0,1]
first_letter >= 'A' && first_letter <= 'Z'
end
|
#create_package_or_class(m) ⇒ Object
92
93
94
95
96
97
98
99
|
# File 'lib/rjb/extension.rb', line 92
def create_package_or_class(m)
method = m.to_s
if class?(method)
Rjb::import("#{self}.#{method}")
else
JavaPackage.new(method, self)
end
end
|
#to_s ⇒ Object
101
102
103
104
105
106
107
|
# File 'lib/rjb/extension.rb', line 101
def to_s
if @parent_pack
"#{@parent_pack.to_s}.#@pack_name"
else
"#@pack_name"
end
end
|