Why are symbols not frozen strings?

前端 未结 6 1916
广开言路
广开言路 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:01

    The basics of it are, these should not be true:

    :apple == "apple"  #=> false, should be true
    
    :apple.hash == "apple".hash #=> false, should be true
    

    Symbols are always the same objects, and text is not.

提交回复
热议问题