Class: Footing::Object

Inherits:
Object
  • 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.

Raises:

  • (ArgumentError)


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_objectObject (readonly)

Returns the value of attribute copied_object.



3
4
5
# File 'lib/footing/object.rb', line 3

def copied_object
  @copied_object
end

#original_objectObject (readonly)

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

Returns:

  • (Boolean)


10
11
12
# File 'lib/footing/object.rb', line 10

def match?(o)
  o.class.ancestors.map(&:name).include?(target_name)
end

.new(o) ⇒ Object



14
15
16
17
# File 'lib/footing/object.rb', line 14

def new(o)
  return o if o.is_a?(self)
  super
end

.target_nameObject



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

Returns:

  • (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