SYNOPSIS
the ruby container you’ve always wanted: a string/symbol indifferent ordered
hash that works in all rubies
Hi Ara,
There is also Stash library (gem install stash -or- gem install
hashery).
One difference between Stash and your Map, is that it uses Strings
rather then Symbols for keys so they can be garbage collected.
Looks like we created these libraries for the same reason. I agree
with your statement “the ruby container you’ve always wanted”. IMO
Ruby’s built-in Hash should work like this because most of the time
that’s really what we want. A Hash that allows for any type key could
be separate class instantiated explicitly.
with your statement “the ruby container you’ve always wanted”. IMO
Ruby’s built-in Hash should work like this because most of the time
that’s really what we want. A Hash that allows for any type key could
be separate class instantiated explicitly.
map does use strings:
big differences between the two libs actually: map is always
ordered. stash does not appear to be…
Ruby’s built-in Hash should work like this because most of the time
that’s really what we want. A Hash that allows for any type key could
be separate class instantiated explicitly.
Ah, your example’s heavy use of symbols made me think otherwise. Very
good.
big differences between the two libs actually: map is always
ordered. stash does not appear to be…
Stash is a subclass of Hash so it will be as ordered as actual Hash,
i.e. 1.8.x no, 1.9 yes.
from (irb):14
The error is technically correct. You’ve assigned a Hash to a Stash as
a value, so you can’t treat the Hash as if it were a Stash. Otherwise
you would never be able to assign an actual Hash as a value. To work
correctly one needs to do:
s.update :k => Stash[:a => Stash[:x => 42]]
I realize automatic conversion might be convenient, but I would be
concerned that it could cause issues.
I might add a #normalize method though that could descend the Stash
and convert all Hash entries and sub-Hash entries to Stashes. I’ll
give it some thought. Thanks.
so there are definitely big differences between the libs at this
point. just FYI.