From b4300d25c941475db902ed2dc667ac23d36be992 Mon Sep 17 00:00:00 2001 From: marcandre Date: Sun, 28 Oct 2012 21:19:15 +0000 Subject: * lib/ostruct.rb: Add OpenStruct#eql? and OpenStruct#hash [ruby-core:42651] [Bug #6029] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/ostruct.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'lib/ostruct.rb') diff --git a/lib/ostruct.rb b/lib/ostruct.rb index e22fca3e46..c00039016a 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -241,7 +241,24 @@ class OpenStruct # equal. # def ==(other) - return false unless(other.kind_of?(OpenStruct)) - return @table == other.table + return false unless other.kind_of?(OpenStruct) + @table == other.table + end + + # + # Compares this object and +other+ for equality. An OpenStruct is eql? to + # +other+ when +other+ is an OpenStruct and the two objects' Hash tables are + # eql?. + # + def eql?(other) + return false unless other.kind_of?(OpenStruct) + @table.eql?(other.table) + end + + # Compute a hash-code for this OpenStruct. + # Two hashes with the same content will have the same hash code + # (and will be eql?). + def hash + @table.hash end end -- cgit v1.2.3