Why are symbols not frozen strings?

前端 未结 6 1922
广开言路
广开言路 2021-01-31 17:59

I understand the theoretical difference between Strings and Symbols. I understand that Symbols are meant to represent a concept or a name or an identifier or a label or a key, a

6条回答
  •  爱一瞬间的悲伤
    2021-01-31 18:18

    See this answer: https://stackoverflow.com/a/6745253/324978

    Main reasons: performance (symbols are stored as integers, and are never garbage collected) and consistency (:admin and :admin will always point to the same object, where "admin" and "admin" don't have that guarantee), etc.

提交回复
热议问题