J
J. Cooper
I ran into something I hadn't realized (common occurrence). Keying a
hash with a symbol is not the same as using a string. I guess it makes
sense, but I've seen it done both ways, and I had been always using
symbols for my keys. But then I ran into an issue on loading an external
YAML object into a hash, and didn't realize it was keyed with strings so
I got errors the first time around.
So two questions:
1) What is the preferred method of keying hashes? Symbols, strings,
other?
2) Is there a smooth way to handle hashes that may have been keyed in
either fashion?
Thanks
hash with a symbol is not the same as using a string. I guess it makes
sense, but I've seen it done both ways, and I had been always using
symbols for my keys. But then I ran into an issue on loading an external
YAML object into a hash, and didn't realize it was keyed with strings so
I got errors the first time around.
So two questions:
1) What is the preferred method of keying hashes? Symbols, strings,
other?
2) Is there a smooth way to handle hashes that may have been keyed in
either fashion?
Thanks