Class: SlappingArray
- Inherits:
-
Object
- Object
- SlappingArray
- Defined in:
- lib/reachable.rb
Instance Attribute Summary collapse
-
#retract ⇒ Object
The array that this reaching array is extending.
Instance Method Summary collapse
-
#==(another) ⇒ Object
Equality test - equality of the underlying retract arrays is all that matter.
-
#initialize(retract) ⇒ SlappingArray
constructor
A new instance of SlappingArray.
-
#method_missing(method, *args, &block) ⇒ Object
Try to pass the method to each of the array members.
- #reach ⇒ Object
- #to_s ⇒ Object
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
#retract ⇒ Object
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 |
#reach ⇒ Object
110 111 112 |
# File 'lib/reachable.rb', line 110 def reach retract.reach end |
#to_s ⇒ Object
106 107 108 |
# File 'lib/reachable.rb', line 106 def to_s method_missing(:to_s) end |