Class: SlappingArray

Inherits:
Object
  • Object
show all
Defined in:
lib/reachable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(retract) ⇒ SlappingArray

Returns a new instance of SlappingArray.



82
83
84
# File 'lib/reachable.rb', line 82

def initialize(retract)
  @retract = retract
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Try to pass the method to each of the array members



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/reachable.rb', line 87

def method_missing(method, *args, &block)
  @retract = @retract.collect do |o|
    unless o.kind_of?(Array)
      o.send(method, *args, &block)
    else
      # Update in 0.2.1: If the element of the array is an array
      # itself, then operate on it as a ReachingArray as well.
      o.slap.send(method, *args, &block).retract
    end
  end
  return self
end

Instance Attribute Details

#retractObject

The array that this reaching array is extending. This might be a real Array, or a ReachingArray



80
81
82
# File 'lib/reachable.rb', line 80

def retract
  @retract
end

Instance Method Details

#==(another) ⇒ Object

Equality test - equality of the underlying retract arrays is all that matter



102
103
104
# File 'lib/reachable.rb', line 102

def ==(another)
  @retract <=> another.retract
end

#reachObject



110
111
112
# File 'lib/reachable.rb', line 110

def reach
  retract.reach
end

#to_sObject



106
107
108
# File 'lib/reachable.rb', line 106

def to_s
  method_missing(:to_s)
end