symbol vs. string

symbol vs. string

http://stackoverflow.com/questions/8189416/why-use-symbols-as-hash-keys-in-ruby

as hash keys, string as keys is duped and  frozen so it cannot be modified. Keys to be frozen is good, but dup may be expensive.

hash.store(key, value) → value

Element Assignment—Associates the value given by value with the key given by key. key should not have its value changed while it is in use as a key (a String passed as a key will be duplicated and frozen).

http://stackoverflow.com/questions/13044839/why-is-a-string-key-for-a-hash-frozen

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s