lib/reach.rb in wwood-reach-0.1.1 vs lib/reach.rb in wwood-reach-0.2.0
- old
+ new
@@ -17,10 +17,14 @@
# the books is an array (bookshelves) of arrays (books)
class Array
def reach
ReachingArray.new(self)
end
+
+ def slap
+ SlappingArray.new(self)
+ end
end
class ReachingArray
# The array that this reaching array is extending. This might
# be a real Array, or a ReachingArray
@@ -55,7 +59,43 @@
@retract <=> another.retract
end
def to_s
@retract.to_s
+ end
+
+ def slap
+ retract.slap
+ end
+end
+
+class SlappingArray
+ # The array that this reaching array is extending. This might
+ # be a real Array, or a ReachingArray
+ attr_accessor :retract
+
+ def initialize(retract)
+ @retract = retract
+ end
+
+ # Try to pass the method to each of the array members
+ def method_missing(method, *args, &block)
+ @retract = @retract.collect do |o|
+ o.send(method, *args, &block)
+ end
+ return self
+ end
+
+ # Equality test - equality of the underlying retract
+ # arrays is all that matter
+ def ==(another)
+ @retract <=> another.retract
+ end
+
+ def to_s
+ @retract.to_s
+ end
+
+ def reach
+ retract.reach
end
end