Delegate DSL-like

This one is a little different. We're using the same code (the printer closure) with two different classes... in this case delegates. Usage examples include the one below, but also things like implemented interfaces or say append in one case adds to a StringBuilder or StringBuffer and in another case it's a stub debug that …

Category DSL

Here's another example. This one using Categories... not quite the happy happy joy joy of other ways of doing DSLs, but it does work. class MyUtility { static Integer getDays(Integer self) { self } static Calendar getAgo(Integer self) { def cal = Calendar.instance cal.add(Calendar.DAY_OF_MONTH, -self) cal } static Date at(Calendar self, Double time) { def …

DND DSL

This comes from the Venkat DSL screencast. Not that you can't type yourself, but it shows a different way to do a DSL than most people think about thePlayers = [:] def players(String[] args) { args.each {player -> thePlayers[player] = 0 } } def getPrint_dice() { thePlayers.each {player, dice -> println "${player} rolled ${dice}" } …