这个结构在 Ruby 中意味着什么?

发布于 2024-08-19 08:24:42 字数 224 浏览 12 评论 0原文

红布宝石中存在以下方法。

我的问题是:“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月苍老的讽刺 2024-08-26 08:24:42

当您在整个 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 with to, you'll also find the exact method to in ext/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 in lib/redcloth/textile_doc.rb are the same. So the to instance method will be available to the piece of code you quoted.

勿挽旧人 2024-08-26 08:24:42

是的,它在 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 be self).

她如夕阳 2024-08-26 08:24:42

可能是在对象或内核模块中定义的。

编辑:不是。它在此文件的第 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文