开发者

What is the difference between :method and :"method$##11" symbol?

Is :"method$##11" format used when special characters comes in开发者_运维知识库side the symbol?


Yes, if your symbol name contains anything other than letters/numbers/underscores, you can quote it instead and it'll still be a symbol (otherwise you will get syntax errors when you don't use the quotes).

Also, using the same name quoted vs unquoted will be treated as the same symbol:

:test == :test2
# => false
:test == "test"
# => false
:test == :"test"
# => true
:test.object_id
# => 144328
:"test".object_id
# => 144328
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜