Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ruby hash comparison starts with comparing hash values

  • Loading branch information...
commit 208c7c9c5156dccd0f1c0b4f7c8076b1bb2f8c4d 1 parent 6fd55a6
@bjornblomqvist bjornblomqvist authored
Showing with 13 additions and 1 deletion.
  1. +4 −0 lib/plucky/extensions/symbol.rb
  2. +9 −1 spec/symbol_operator_spec.rb
View
4 lib/plucky/extensions/symbol.rb
@@ -73,6 +73,10 @@ def <=>(other)
field.to_s <=> other.field.to_s
end
end
+
+ def hash
+ field.hash + operator.hash
+ end
def ==(other)
other.class == self.class && field == other.field && operator == other.operator
View
10 spec/symbol_operator_spec.rb
@@ -34,7 +34,15 @@
SymbolOperator.new(:foo, 'in').should_not == 'foo.in'
end
end
-
+
+ context "hash" do
+
+ it 'returns sum of operator and hash field' do
+ SymbolOperator.new(:foo, 'in').hash.should == :foo.hash + 'in'.hash
+ end
+
+ end
+
context "<=>" do
it "returns string comparison of operator for same field, different operator" do
(SymbolOperator.new(:foo, 'in') <=> SymbolOperator.new(:foo, 'all')).should == 1
Please sign in to comment.
Something went wrong with that request. Please try again.