【发布时间】:2011-07-06 15:38:39
【问题描述】:
符号中出现特殊字符时是否使用:"method$##11" 格式?
【问题讨论】:
-
你是怎么得到这个字符串的?
-
@phtrivier..
"method$##11".to_sym -
:"You can even put spaces in when you have quotation marks."
符号中出现特殊字符时是否使用:"method$##11" 格式?
【问题讨论】:
"method$##11".to_sym
:"You can even put spaces in when you have quotation marks."
是的,如果您的符号名称包含字母/数字/下划线以外的任何内容,您可以引用它,它仍然是一个符号(否则当您不使用引号时会出现语法错误)。
另外,使用相同的名称引用和不引用将被视为相同的符号:
:test == :test2
# => false
:test == "test"
# => false
:test == :"test"
# => true
:test.object_id
# => 144328
:"test".object_id
# => 144328
【讨论】: