3 ms·
I'm not too sure where most of these examples fall on the line between DSLs and just regular CoffeeScript functions (I think the latter), but to pitch in with a
by jashkenas 16y ago
I'm not too sure where most of these examples fall on the line between DSLs and just regular CoffeeScript functions (I think the latter), but to pitch in with another, here's Arel DB querying:
Post.where published: yes
Account.joins('customer').where customer: name: 'Pepsi'
Which compiles into this JavaScript:
Post.where({
published: true
});
Account.joins('customer').where({
customer: {
name: 'Pepsi'
}
});
- rst 16y agoWell, you could also say the Ruby examples are just invoking regular Ruby functions. Either way, you've got what Martin Fowler[1] calls an "internal DSL" (as opposed to an "external DSL", which has a parser and syntax of its own). [1] http://martinfowler.com/bliki/DomainSpecificLanguage.html http://martinfowler.com/bliki/DomainSpecificLanguage.html