Ruby 语言中的 %q、%w 等在哪里定义? [英] Where in the Ruby language is %q, %w, etc., defined?
问题描述
Ruby 语言的大部分内容是方法而不是语法,所以我希望找到 %q
、%w
等,定义为 Kernel
类.然而,他们不在那里.
So much of the Ruby language is methods rather than syntax, so I expected to find %q
, %w
, etc., defined as methods in the Kernel
class. However, they're not there.
那么它们是在哪里定义的呢?它们是语言关键字吗?
So where are they defined? Are they language keywords?
推荐答案
它们在解析器中是硬编码"的;见
They are "hard coded" in the parser; see
查找相关代码的最简单方法是查找第二次出现的 str_sword
(单引号词).所有分隔输入"语法都在此处定义:%Q
、%q
、%W
、%w
、%x
、%r
和 %s
(上面引用的两个版本都定义了相同的分隔输入标记集).
The easiest way to find the code in question is to look for the second occurrence of str_sword
(Single-quoted WORDs). All the "delimited input" syntax is defined there: %Q
, %q
, %W
, %w
, %x
, %r
, and %s
(both versions referenced above define the same set of delimited input markers).
这篇关于Ruby 语言中的 %q、%w 等在哪里定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!