Ruby DSL experience?

I don't know anything in Ruby, but I'm very interested in DSL. And DSL seems to be a buzzword for your community.

Do you really implement DSL in Ruby for your own purposes? If so, how complex are they and how dedicated are they?

I saw a question here , but I'm more interested in your daily experience.

thank.

+3
source share
3 answers

Here is another example of Ruby DSL called Mail and DSL for sending emails:

mail = Mail.new do
    to 'nicolas@test.lindsaar.net.au'
    from 'Mikel Lindsaar <mikel@test.lindsaar.net.au>'
    subject 'First multipart email sent with Mail'
end

see here: http://github.com/mikel/mail

+3
source

My own experience writing DSL in Ruby is pretty limited, but I did the following:

(1) DSL L-System:

Dragon = TexPlay::LSystem.new {
    rule "F" => "F"
    rule "X" => "X+YF+"
    rule "Y" => "-FX-Y"
    angle 90

    atom "FX"
}

(2) Image processing tool:

image.paint {
    circle 20, 20, 15, :color => :red
    rect 10, 20, 100, 100, :color => :green
    pixel 40, 40, :color => :white
}
+2

Ruby’s specialty is for everything to work very fast, but it can become difficult to handle. I would say that for small or medium-sized DSL projects, ruby ​​is terrific. Since I did not create any large DSL project in Ruby, I cannot recommend it (for larger projects).

0
source

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


All Articles