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.
This commit is contained in:
parent
43f0c63135
commit
50c7c6bbd6
@ -292,12 +292,11 @@ class Formula
|
|||||||
@pin.unpin
|
@pin.unpin
|
||||||
end
|
end
|
||||||
|
|
||||||
def == b
|
def == other
|
||||||
name == b.name
|
instance_of?(other.class) && name == other.name
|
||||||
end
|
|
||||||
def eql? b
|
|
||||||
self == b and self.class.equal? b.class
|
|
||||||
end
|
end
|
||||||
|
alias_method :eql?, :==
|
||||||
|
|
||||||
def hash
|
def hash
|
||||||
name.hash
|
name.hash
|
||||||
end
|
end
|
||||||
|
|||||||
@ -124,6 +124,10 @@ class FormulaTests < Test::Unit::TestCase
|
|||||||
assert !y.eql?(x)
|
assert !y.eql?(x)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_comparison_with_non_formula_objects_does_not_raise
|
||||||
|
assert_not_equal TestBall.new, Object.new
|
||||||
|
end
|
||||||
|
|
||||||
def test_class_naming
|
def test_class_naming
|
||||||
assert_equal 'ShellFm', Formula.class_s('shell.fm')
|
assert_equal 'ShellFm', Formula.class_s('shell.fm')
|
||||||
assert_equal 'Fooxx', Formula.class_s('foo++')
|
assert_equal 'Fooxx', Formula.class_s('foo++')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user