diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-10-28 21:19:15 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-10-28 21:19:15 +0000 |
commit | b4300d25c941475db902ed2dc667ac23d36be992 (patch) | |
tree | 1505baa640a703a09b9dc89cb93cdb354d611a95 /lib | |
parent | 15d4862b913f6d555ce8a79075d69bba74b5b9bc (diff) | |
download | ruby-b4300d25c941475db902ed2dc667ac23d36be992.tar.gz |
* 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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ostruct.rb | 21 |
1 files changed, 19 insertions, 2 deletions
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 |