aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/compilers.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/compilers.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/compilers.rb')
-rw-r--r--Library/Homebrew/compilers.rb44
1 files changed, 35 insertions, 9 deletions
diff --git a/Library/Homebrew/compilers.rb b/Library/Homebrew/compilers.rb
index 03a1de6bc..eaaf041b5 100644
--- a/Library/Homebrew/compilers.rb
+++ b/Library/Homebrew/compilers.rb
@@ -1,19 +1,45 @@
-class Compilers < Array
- def include? cc
+class Compilers
+ include Enumerable
+
+ def initialize(*args)
+ @compilers = Array.new(*args)
+ end
+
+ def each(*args, &block)
+ @compilers.each(*args, &block)
+ end
+
+ def include?(cc)
cc = cc.name if cc.is_a? Compiler
- self.any? { |c| c.name == cc }
+ @compilers.any? { |c| c.name == cc }
+ end
+
+ def <<(o)
+ @compilers << o
+ self
end
end
-class CompilerFailures < Array
- def include? cc
+class CompilerFailures
+ include Enumerable
+
+ def initialize(*args)
+ @failures = Array.new(*args)
+ end
+
+ def each(*args, &block)
+ @failures.each(*args, &block)
+ end
+
+ def include?(cc)
cc = Compiler.new(cc) unless cc.is_a? Compiler
- self.any? { |failure| failure.compiler == cc.name }
+ @failures.any? { |failure| failure.compiler == cc.name }
end
- def <<(failure)
- super(failure) unless self.include? failure.compiler
+ def <<(o)
+ @failures << o unless include? o.compiler
+ self
end
end
@@ -72,7 +98,7 @@ class CompilerSelector
# @compilers is our list of available compilers. If @f declares a
# failure with compiler foo, then we remove foo from the list if
# the failing build is >= the currently installed version of foo.
- @compilers.reject! do |cc|
+ @compilers = @compilers.reject do |cc|
failure = @f.fails_with? cc
next unless failure
failure.build >= cc.build