summaryrefslogtreecommitdiff
path: root/lib/ostruct.rb
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-28 21:19:15 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-28 21:19:15 +0000
commitb4300d25c941475db902ed2dc667ac23d36be992 (patch)
tree1505baa640a703a09b9dc89cb93cdb354d611a95 /lib/ostruct.rb
parent15d4862b913f6d555ce8a79075d69bba74b5b9bc (diff)
* 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/ostruct.rb')
-rw-r--r--lib/ostruct.rb21
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index e22fca3..c000390 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