Bug #6029

Should OpenStruct implement #eql? and #hash?

Added by Marc-Andre Lafortune about 3 years ago. Updated over 2 years ago.

[ruby-core:42651]
Status:Closed
Priority:Normal
Assignee:Marc-Andre Lafortune
ruby -v:r34620 Backport:

Description

Currently, OpenStruct have no specialized #eql? and #hash, so:

require 'ostruct'
x = OpenStruct.new(foo: 42)
y = x.dup
x == y    # => true
x.eql?(y) # => false

This means that OpenStruct does not behave like Struct, Array, Hash and other structures by comparing its fields and values.

This also prevents using OpenStructs as hash keys (unless one uses the exact same object as the key), contrary to other structures.

Is there an historical reason for this?

How likely would it be that adding #eql? and #hash create conflict with some fields?


Related issues

Related to Ruby trunk - Feature #6056: Enhancements to OpenStruct Closed 02/21/2012

Associated revisions

Revision 37373
Added by Marc-Andre Lafortune over 2 years ago

  • lib/ostruct.rb: Add OpenStruct#eql? and OpenStruct#hash [Bug #6029]

Revision 37373
Added by Marc-Andre Lafortune over 2 years ago

  • lib/ostruct.rb: Add OpenStruct#eql? and OpenStruct#hash [Bug #6029]

History

#1 Updated by Shyouhei Urabe about 3 years ago

  • Status changed from Open to Assigned

#2 Updated by Marc-Andre Lafortune over 2 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r37373.
Marc-Andre, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • lib/ostruct.rb: Add OpenStruct#eql? and OpenStruct#hash [Bug #6029]

Also available in: Atom PDF