How to Write a Ruby DSL

1 min read Original article ↗

Azzen Abidi

Or how I created a language for Notion Templates

Press enter or click to view image in full size

Photo by Desola Lanre-Ologun on Unsplash

I am a Notion fan. I have been using it consistently since 2020. I enjoy creating templates but I am too slow. I wanted a better way. That’s how DSLs came to mind.

Now I have known about DSL for years now since I use Ruby on Rails but I have never seen it in action.

The idea of the ruby gem came out a bit later. Initially I wanted a proof of concept so my goal was a simple ruby script.

In this tutorial, I will walk you step by step on how I built the ruby gem.

Assumptions

The tutorial assumes the following:

  • You have a basic programming knowledge (bonus if you know ruby but not required)
  • You have Ruby installed
  • You have a Notion account (it’s free)
  • You know Git and Github

“A ruby gem is a way to package a collection of ruby code into one unit.”

What’s a DSL

Martin Fowler defines DSLs as follows:

“A Domain-Specific Language (DSL) is a computer language that’s targeted to a particular…