This project is archived and is in readonly mode.
Subclasses of HashWithIndifferentAccess dup the wrong class
Reported by Steve Richert | September 28th, 2010 @ 03:56 PM
There are two instances of
HashWithIndifferentAccess
being named explicitly in
its own class. No bug there, but if a new class is created that
inherits from HashWithIndifferentAccess
, the
new_from_hash_copying_default
class method and the
dup
instance method incorrectly return an instance of
HashWithIndifferentAccess
rather than the
newly-created class.
class FooHash < HashWithIndifferentAccess
end
foo = FooHash.new # => {}
foo.class # => FooHash
bar = foo.dup # => {}
bar.class # => HashWithIndifferentAccess
Comments and changes to this ticket
-
Steve Richert September 28th, 2010 @ 04:00 PM
Patched, with no tests as it seems pretty straightforward.
-
laserlemon September 29th, 2010 @ 05:20 PM
- Tag changed from duplicate, hashwithindifferentaccess to hashwithindifferentaccess
-
David Trasbo October 10th, 2010 @ 04:51 PM
- State changed from new to incomplete
- Importance changed from to Low
+1, but:
Rule no. 1: Always add tests. This is no exception. :)
And I'd replace
self.class.new
with justclass.new
. -
laserlemon October 11th, 2010 @ 12:10 PM
Here's a new patch including tests. I also discovered that HashWithIndifferentAccess duplication doesn't preserve a default value so I resolved that issue as well. Thank you!
-
laserlemon October 11th, 2010 @ 12:14 PM
I should also mention that
class.new
isn't valid Ruby, so I stuck withself.class.new
. -
David Trasbo October 11th, 2010 @ 06:57 PM
Ah, ok. Silly me, didn't think about that!
Anyways: +1
Patch applies cleanly and tests pass. Please do unify all the commits in the patch, though.
-
laserlemon October 12th, 2010 @ 02:25 AM
Thanks again for the advice. Here's a new, single-commit diff with a message resolving the ticket.
-
ara.t.howard October 12th, 2010 @ 03:39 AM
some people might be interested in this:
i've fought long and hard with HashWithIndiffentAccess and finally broke down and merged it with OrderedHash - Map is the result. it fixes the issue in this thread too.
-
Repository November 7th, 2010 @ 12:21 PM
- State changed from incomplete to resolved
(from [02039e9752bcb214c2ad85859ecf47dcbb892225]) Ensure that HashWithIndifferentAccess duplication preserves class (for sublclasses) and default value [#5724 state:resolved]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
https://github.com/rails/rails/commit/02039e9752bcb214c2ad85859ecf4...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 5724 Subclasses of HashWithIndifferentAccess dup the wrong class (from [02039e9752bcb214c2ad85859ecf47dcbb892225]) Ensure ...