summaryrefslogtreecommitdiff
path: root/ruby/cmp.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ruby/cmp.rb')
-rwxr-xr-xruby/cmp.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/ruby/cmp.rb b/ruby/cmp.rb
new file mode 100755
index 0000000..65e5c5f
--- /dev/null
+++ b/ruby/cmp.rb
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+
+
+class A
+ attr_accessor :a
+
+ def initialize a
+ @a = a
+ end
+
+ def == other
+ @a.size == other.a.size
+ end
+ alias :eql? :==
+
+ def hash
+ @a.hash
+ end
+end
+
+a = A.new 'a'
+b = A.new 'b'
+ax = A.new 'a'
+
+puts a == ax
+
+l = [a, b, ax]
+puts l.uniq.size
+