Module: Hatt::SingletonMixin
- Defined in:
- lib/hatt/singleton_mixin.rb
Defined Under Namespace
Classes: InitOnceHattClass
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *arguments, &block) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/hatt/singleton_mixin.rb', line 14
def method_missing(method_id, *arguments, &block)
if hatt_instance_has_method?(method_id)
hatt_instance.send(method_id, *arguments, &block)
else
super
end
end
|
Class Method Details
.hatt_instance ⇒ Object
9
10
11
|
# File 'lib/hatt/singleton_mixin.rb', line 9
def hatt_instance
@@hatt_instance ||= InitOnceHattClass.new
end
|
Instance Method Details
#hatt_instance_has_method?(name, include_private = false) ⇒ Boolean
22
23
24
25
26
27
28
|
# File 'lib/hatt/singleton_mixin.rb', line 22
def hatt_instance_has_method?(name, include_private = false)
if include_private
hatt_instance.methods.include?(name.to_sym)
else
hatt_instance.public_methods.include?(name.to_sym)
end
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
30
31
32
|
# File 'lib/hatt/singleton_mixin.rb', line 30
def respond_to_missing?(name, include_private = false)
hatt_instance_has_method?(name, include_private) || super
end
|