Skip to content

Instantly share code, notes, and snippets.

@vkoloss
Created June 1, 2016 10:41
Show Gist options
  • Save vkoloss/accf1fd6b60c7cc0543bc6ca9b6a5221 to your computer and use it in GitHub Desktop.
Save vkoloss/accf1fd6b60c7cc0543bc6ca9b6a5221 to your computer and use it in GitHub Desktop.
class WorkingDay {
def schedule = []
WorkingDay() {
def mc = new ExpandoMetaClass(WorkingDay, false, true)
mc.initialize()
this.metaClass = mc
}
def methodMissing(String name, args) {
if (name.startsWith('work')) {
schedule << "talk to girls"
} else {
schedule << "$name ${args[0]}"
}
this.metaClass."$name" = {argz -> schedule << "$name ${args[0]} again" }
}
def plan() {
println "Today I am going to $schedule"
}
}
def I = new WorkingDay()
I.eat 'breakfast'
I.take 'shower'
I.workOn 'XYZ-4350'
I.enjoy 'massage'
I.take 'shower'
I.go 'home'
I.plan()
@vkoloss
Copy link
Author

vkoloss commented Jun 1, 2016

Basic DSL on Groovy for demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment