今天看 HighLine 库的源码意外发现的,语法是一个问号紧跟一个字符,等价于这个只含一个该字符的字符串:
require "minitest/autorun"
describe "?y" do
it "is the same thing as 'y'" do
?y.must_equal 'y'
end
end
翻了一下镐头书第三版,里面居然有收纳这个语法。并且给出了这样的评价:
Do yourself a favor and immediately forget this section. It’s far easier to use regular octal and hex escape sequences than to remember these ones. Use "a" rather than ?a, and use "\n" rather than ?\n.
出于装 X 的考虑,以后要找机会多用 www