views:

1654

answers:

4

I am seeking excellent examples of Ruby DSLs (Domain Specific Languages). Which repositories, projects do you know of that are worth a read? Why is it (or: are they) great examples?

I am particularly interested in more complex examples that are well thought-out and designed.

+1  A: 

Some good ruby DSLs I can think of are hpricot and sinatra

Craig
The structure of sinatra is really nice. Had heard about it but not looked at it. Thanks for the reminder.
Demi
+2  A: 

Rake and Rack are some good examples of DSL's. If you want some more examples, check these out:

  • Sinatra is a very popular DSL for building web applications, and it's open source on GitHub.
  • Twibot is a newer DSL inspired by Sinatra that lets you create Twitter bots that automatically respond to messages and replies.

If you want to get started on making your own, here's an excellent tutorial called Building a DSL in Ruby.

Justin Poliey
Twibot is an interesting find I'll look at. Thanks!
Demi
+1  A: 

Another example, of course, is Rake, the Ruby build system. What makes a DSL "good" in my opinion:

  1. Notation conforms to meaning, i.e. if you read a sentence (statement) in the DSL, you have a clear, unambiguous idea of what it does.
  2. Domain-specific, i.e. the DSL does not solve every problem in the universe but rather focuses on one little domain (such as building software, querying data, or contructing UIs)
  3. High-level of abstraction. A DSL uses high-level concepts that the programmer can use, and translates those to a lower-level implementation (internally). In the case of Rake the main concept the language is based on are tasks and dependencies between them.
Zef Hemel
+2  A: 

In the area of Behaviour-Driven Development you can check out:

  • Cucumber - Describe BDD using scenarios
  • RSpec - Replace testing code with specifying behaviours.

Though I have to admit the RSpec code leaves me scratching my head sometimes because I'm still very much a novice.

Mike Bethany