aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorJack Nagel2013-10-04 21:19:15 -0500
committerJack Nagel2013-10-04 21:19:15 -0500
commit50c7c6bbd6eac0dfb1d3c48e7d0ee49e667b315c (patch)
treefb8bdef10c529354207500ed336f6f866919573e /Library/Homebrew
parent43f0c631357a01f01cea20ebad6d136388689fec (diff)
downloadbrew-50c7c6bbd6eac0dfb1d3c48e7d0ee49e667b315c.tar.bz2
Check types in Formula#==
Comparing two objects should not raise an exception, even if they have different types. The semantics of #== are now the same as #eql?, so make one an alias.
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/formula.rb9
-rw-r--r--Library/Homebrew/test/test_formula.rb4
2 files changed, 8 insertions, 5 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 09ddf45ff..391b3b322 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -292,12 +292,11 @@ class Formula
@pin.unpin
end
- def == b
- name == b.name
- end
- def eql? b
- self == b and self.class.equal? b.class
+ def == other
+ instance_of?(other.class) && name == other.name
end
+ alias_method :eql?, :==
+
def hash
name.hash
end
diff --git a/Library/Homebrew/test/test_formula.rb b/Library/Homebrew/test/test_formula.rb
index 1591b425b..bc1e703eb 100644
--- a/Library/Homebrew/test/test_formula.rb
+++ b/Library/Homebrew/test/test_formula.rb
@@ -124,6 +124,10 @@ class FormulaTests < Test::Unit::TestCase
assert !y.eql?(x)
end
+ def test_comparison_with_non_formula_objects_does_not_raise
+ assert_not_equal TestBall.new, Object.new
+ end
+
def test_class_naming
assert_equal 'ShellFm', Formula.class_s('shell.fm')
assert_equal 'Fooxx', Formula.class_s('foo++')