aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/dependencies.rb
diff options
context:
space:
mode:
authorJack Nagel2013-01-07 14:06:34 -0600
committerJack Nagel2013-01-07 14:32:14 -0600
commit429caf69a9bc3f86e510933d45c8d0cad6db7d10 (patch)
tree74326988360354892eb1a21b5f95906ff42e0915 /Library/Homebrew/dependencies.rb
parent7473d2b12f8e39385df3e34a8d4e49655a403d3a (diff)
downloadbrew-429caf69a9bc3f86e510933d45c8d0cad6db7d10.tar.bz2
Remove Array subclassing
Inheriting from Array (and other core types) is problematic: - It exposes a very wide interface with many methods that are not really relevant to the subclass. - It can cause some weird side effects, as many Array operations are in C and have hardcoded return values; for example, combining two array subclasses returns a new Array instead of the subclass. Avoid these problems using delegation and the Enumerable module where applicable.
Diffstat (limited to 'Library/Homebrew/dependencies.rb')
-rw-r--r--Library/Homebrew/dependencies.rb23
1 files changed, 20 insertions, 3 deletions
diff --git a/Library/Homebrew/dependencies.rb b/Library/Homebrew/dependencies.rb
index 0e4d4be2f..3dd5a3101 100644
--- a/Library/Homebrew/dependencies.rb
+++ b/Library/Homebrew/dependencies.rb
@@ -85,11 +85,28 @@ private
end
+class Dependencies
+ include Enumerable
+
+ def initialize(*args)
+ @deps = Array.new(*args)
+ end
+
+ def each(*args, &block)
+ @deps.each(*args, &block)
+ end
-# A list of formula dependencies.
-class Dependencies < Array
def <<(o)
- super(o) unless include? o
+ @deps << o unless @deps.include? o
+ self
+ end
+
+ def empty?
+ @deps.empty?
+ end
+
+ def *(arg)
+ @deps * arg
end
end