Project

General

Profile

ActionsLike0

Bug #6029

closed

Should OpenStruct implement #eql? and #hash?

Added by marcandre (Marc-Andre Lafortune) about 13 years ago. Updated over 12 years ago.

Status:
Closed
Target version:
ruby -v:
r34620
Backport:
[ruby-core:42651]

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 1 (0 open1 closed)

Related to Ruby - Feature #6056: Enhancements to OpenStructClosedmarcandre (Marc-Andre Lafortune)02/21/2012Actions
#1

Updated by shyouhei (Shyouhei Urabe) about 13 years ago

  • Status changed from Open to Assigned
#2

Updated by marcandre (Marc-Andre Lafortune) over 12 years ago

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

Also available in: Atom PDF