Ruby ate my DSL!
summary
Claim: DSLs are still just Ruby so user code can stomp internals. Demonstration builds a tiny nanospec (about 20 lines of code) that mostly works but breaks when user code runs via instance_eval, e.g. Sinatra’s private invoke collision. Techniques shown: prefix internal names, split the DSL interface from its implementation and delegate, minimize scope by extending only the main object, prefer class modeling and class_eval for lexical helpers, avoid BasicObject, and provide alternatives to constants (RSpec’s let) to make the DSL behave more like Ruby.
AI-written summary · about
chapters (12)
- 0:00Intro
- 1:28Sinatra bug
- 4:15Introduction
- 7:43Rails
- 9:16Extending Ruby
- 18:30Rehave
- 21:41Helper Methods
- 25:35lexical scoping
- 31:51constants
- 33:11provide alternatives
- 33:59recap
- 34:58DSL vs Ruby
related talks
25mMore DSL, Less Pain
01h 10mDomain Specific Languages: Molding Ruby
38mDSLs, Code Generation, and New Domains for Ruby
36ms/regex/DSLs/: What Regex Teaches Us About DSL Design
40mWorst. Ideas. Ever.
37mImplicit to Explicit: Decoding Ruby's Magical Syntax
30mRuby Techniques by Example
31mSeeing Metaprogramming and Lambda Function Patterns in Ruby
