【问题标题】:What is the difference between :method and :"method$##11" symbol?:method 和 :"method$##11" 符号有什么区别?
【发布时间】:2011-07-06 15:38:39
【问题描述】:

符号中出现特殊字符时是否使用:"method$##11" 格式?

【问题讨论】:

  • 你是怎么得到这个字符串的?
  • @phtrivier.."method$##11".to_sym
  • :"You can even put spaces in when you have quotation marks."

标签: ruby symbols


【解决方案1】:

是的,如果您的符号名称包含字母/数字/下划线以外的任何内容,您可以引用它,它仍然是一个符号(否则当您不使用引号时会出现语法错误)。

另外,使用相同的名称引用和不引用将被视为相同的符号:

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

【讨论】:

    猜你喜欢
    • 2013-04-11
    • 1970-01-01
    • 2013-09-17
    • 2011-09-26
    • 2019-08-21
    • 1970-01-01
    • 2017-02-28
    • 2014-09-14
    • 1970-01-01
    相关资源
    最近更新 更多