Class: Footing::Object
- Inherits:
-
Object
show all
- Defined in:
- lib/footing/object.rb
Direct Known Subclasses
Hash
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(o) ⇒ Object
Returns a new instance of Object.
20
21
22
23
24
|
# File 'lib/footing/object.rb', line 20
def initialize(o)
raise ArgumentError.new("Types must match") unless self.class.match?(o)
@original_object = o
@copied_object = o.dup
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/footing/object.rb', line 26
def method_missing(name, *args)
if copied_object.respond_to?(name)
return copied_object.send name, *args
end
super
end
|
Instance Attribute Details
#copied_object ⇒ Object
Returns the value of attribute copied_object.
3
4
5
|
# File 'lib/footing/object.rb', line 3
def copied_object
@copied_object
end
|
#original_object ⇒ Object
Returns the value of attribute original_object.
3
4
5
|
# File 'lib/footing/object.rb', line 3
def original_object
@original_object
end
|
Class Method Details
.match?(o) ⇒ Boolean
10
11
12
|
# File 'lib/footing/object.rb', line 10
def match?(o)
o.class.ancestors.map(&:name).include?(target_name)
end
|
14
15
16
17
|
# File 'lib/footing/object.rb', line 14
def new(o)
return o if o.is_a?(self)
super
end
|
.target_name ⇒ Object
6
7
8
|
# File 'lib/footing/object.rb', line 6
def target_name
self.name.gsub(/\AFooting::/, "")
end
|
Instance Method Details
#respond_to?(name) ⇒ Boolean
34
35
36
37
|
# File 'lib/footing/object.rb', line 34
def respond_to?(name)
return true if copied_object.respond_to?(name)
super
end
|