Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

chromatic (983)

chromatic
  (email not shown publicly)
http://wgz.org/chromatic/

Blog Information [technorati.com] Profile for chr0matic [technorati.com]

Journal of chromatic (983)

Saturday February 16, 2008
04:42 PM

Implementing an Internal DSL in Ruby (simplified version)

[ #35675 ]

If you're like me, your attention span on a three-day weekend is too short to wade through all of Implementing an Internal DSL in Ruby. I've decided to be helpful to all of the confused people in the world who just don't see the special magic that goes in to writing an internal DSL. Here's the condensed version which helpfully fits on an index card. (That way, you can palm it at the next Rails meetup if you need a cheat sheet.)

  1. Create a class.
  2. Declare class methods in that class. These methods should take blocks as their only arguments. These methods should execute those blocks.
  3. Use the class in your programs.

If this doesn't sound very spectacular, you're absolutely right. I thought it important to take a break before the final, magical step which turns bog-standard rote programming into unicorn-and-glitter wonderful tooth-whitening DSL creation.

  • Pat yourself on the back vigorously, repeatedly, and noisily in full public view of everyone who might ever have a passing interest in computers, even if that interest is solely in the game Minesweeper.

Congratulations! Unlike the poor slobs who merely declare classes and methods, give them meaningful names, and occasionally pass around first-class functions, YU WRITED AN DSL!! GRATE JOBZES!!!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • i only skimmed that one first time past thinking "Well, it's a wee bit content light", but on second reading...

    That took him months?

    Frankly, I don't start to think it might be a pidgin until the code in those blocks starts looking pretty damned unrubylike. Class methods are for introducing the weird scope you need to make your declarative style pidgin work. Perl libraries like Jifty::DBI::Schema do something similar, they just have a different toolchain and 'feel' to them because Perl's prototyping pushes t