What does this construct mean in Ruby?

The following is the method described in the pearl of red fabric.

My question is: what does the "to (RedCloth :: Formatters :: HTML)" construct mean? "to" is not a method in a class, nor in a superclass (which is a String class).

Greetings. Christian.

def to_html( *rules ) apply_rules(rules) to(RedCloth::Formatters::HTML) end 
+4
source share
3 answers

When you browse the entire RedCloth source for def to , in addition to searching for a few methods starting with to , you will also find the exact to method in ext/redcloth_scan/redcloth_scan.rb.rl .

There are two things here. Firstly, this file is pre-processed by Ragel . But on this subject, you can safely ignore this fact and read the last strange syntax in this file. Focus on the Ruby bits.

Secondly, the RedCloth::TextileDoc class RedCloth::TextileDoc . This means that the class in this file and in lib/redcloth/textile_doc.rb match. This way, the to instance method will be available for the code snippet you specified.

+7
source

Yes, it is defined in http://github.com/jgarber/redcloth/blob/master/ext/redcloth_scan/redcloth_scan.c.rl on line 200 and is attached to the class at 221.

to(RedCloth::Formatters::HTML) simply calls the #to method and passes it to the formatting class (the second argument in the redcloth_to C method, the first should always be self ).

0
source

Maybe it is defined in an object or in a kernel module.

EDIT: no. It is defined on line 220 of this file http://github.com/jgarber/redcloth/blob/master/ext/redcloth_scan/redcloth_scan.c.rl

-one
source

Source: https://habr.com/ru/post/1299672/


All Articles