summaryrefslogtreecommitdiff
path: root/lib/ostruct.rb
diff options
context:
space:
mode:
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 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