这个结构在 Ruby 中意味着什么?
红布宝石中存在以下方法。
我的问题是:“to(RedCloth::Formatters::HTML)
”结构是什么意思? “to”不是类中的方法,也不是超类(String 类)中的方法。
def to_html( *rules )
apply_rules(rules)
to(RedCloth::Formatters::HTML)
end
The method below exists in the Redcloth gem.
My question is: what does the construction "to(RedCloth::Formatters::HTML)
" mean? "to" isn't a method in the class, nor in the superclass (which is String class).
def to_html( *rules )
apply_rules(rules)
to(RedCloth::Formatters::HTML)
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您在整个 RedCloth 源代码中搜索
def to
时,除了找到几个以to
开头的方法之外,您还会找到确切的方法to
代码> 在ext/redcloth_scan/redcloth_scan.rb.rl
中。这里发生了两件事。首先,该文件由 Ragel 进行预处理。但对于这个问题,您可以安全地忽略这个事实并阅读该文件中奇怪的语法。专注于 Ruby 位。
其次,类
RedCloth::TextileDoc
在这里重新打开。这意味着该文件中的类与 lib/redcloth/textile_doc.rb 中的类相同。因此to
实例方法将可用于您引用的代码段。When you search the entire RedCloth source for
def to
, besides finding a couple of methods that start withto
, you'll also find the exact methodto
inext/redcloth_scan/redcloth_scan.rb.rl
.There's two things that happen here. First, this file is preprocessed by Ragel. But for this question, you may safely ignore this fact and read past the weird syntax in that file. Focus on the Ruby bits.
Second, the class
RedCloth::TextileDoc
is reopend here. That means the class in this file and inlib/redcloth/textile_doc.rb
are the same. So theto
instance method will be available to the piece of code you quoted.是的,它在 http://github 中定义。 com/jgarber/redcloth/blob/master/ext/redcloth_scan/redcloth_scan.c.rl 在第 200 行,并附加到第 221 行的类。
to(RedCloth::Formatters::HTML)
只是调用 #to 方法并传入格式化程序的类(redcloth_to C 方法中的第二个参数;第一个参数必须始终是self
)。Yes, it's defined at in http://github.com/jgarber/redcloth/blob/master/ext/redcloth_scan/redcloth_scan.c.rl at line 200 and attached to the class at 221.
to(RedCloth::Formatters::HTML)
is just calling the #to method and passing in the class of the formatter (the second argument in the redcloth_to C method; the first must always beself
).可能是在对象或内核模块中定义的。
编辑:不是。它在此文件的第 220 行定义 http:// github.com/jgarber/redcloth/blob/master/ext/redcloth_scan/redcloth_scan.c.rl
Could be it's defined on Object or in Kernel module.
EDIT: it's not. It's defined on line 220 of this file http://github.com/jgarber/redcloth/blob/master/ext/redcloth_scan/redcloth_scan.c.rl