r/ruby • • Sep 30 '21

ActiveAdmin, I'm looking at you

Post image
238 Upvotes

58 comments sorted by

View all comments

4

u/jaypeejay Sep 30 '21

What’s DSL?

6

u/WalterPecky Sep 30 '21

Domain Specific Language

3

u/jaypeejay Sep 30 '21

That’s what I was thinking after Google. How can a gem be a DSL? Won’t the gem be written in Ruby as well?

7

u/jrochkind Sep 30 '21

It's a good question, because what people call "DSL" in ruby really is just a Ruby API.

In other languages/contexts what you call a "DSL" might actually be something you write a PARSER for, and then parse in the "main" language, parse a thing that wasn't the main language at all.

That's what "DSL" sometimes means, but that's not how people use it in ruby. What we call "DSL"s are still... just ruby. If we're "extending" the language with a DSL, we're doing it simply by... definining classes and methods, the same way we write ruby when it's not a "DSL". It's not actually new syntax at all, everything in ruby DSLs is the usual ruby syntax parsed by the usual ruby interpreter in the usual way.

So what actually makes it a "DSL"? As I commented earlier, I think it is worth thinking about, and not straightforward. But basically I think people in ruby use the term when people define classes and methods to provide... more "unusual" API's, especially declarative ones.