Ticket #94 (new enhancement)

Opened 3 years ago

Last modified 2 years ago

full support for symbols as registry keys

Reported by: alex Assigned to: giblet
Priority: normal Milestone:
Component: misc Version:
Severity: minor Keywords:
Cc:

Description

There are some issues when trying to use a :symbol as registry key. After @registry[:blah] = 1, the enumerator @registry.each will return the key as "blah" rather than as :blah.

Ironically, the documentation for the Registry class uses a symbol as example key.

Change History

06/02/06 12:55:43 changed by giuseppe.bilotta

Try @registry.each_key { |k| puts k.class } --does it say Symbol or String?

06/02/06 15:04:51 changed by epitron

It makes sense to use strings in the database internally -- it saves us having to marshal the key before writing the data, and makes the database index more sane (instead of all this high-bit ascii junk).

An easy way to work around this problem is to allow dbhash to accept symbols and strings when looking up records by just converting the key to a string before passing it to the database.

Would that let you do what you want alex?

06/02/06 17:46:09 changed by alex

My problem was that one plugin (roulette) uses users' nicknames as hash keys, and I originally intended to use :symbols for some additional keys so that they wouldn't collide with the nicknames. Which doesn't work as the symbols end up as strings anyway. I did some more checking, and it seems that in fact any key object is converted into a string. I tried [1, 2] as key, and it came out as "12".

It's easy enough to work around that problem, I just thought that having symbol keys that don't collide with string keys would be a nice thing. Hence I marked this only as an "enhancement". Maybe there should be a comment in Registry saying that all keys should be strings?