Skip to content

Instantly share code, notes, and snippets.

@BenjaminHerbert
Created October 12, 2016 19:56
Show Gist options
  • Save BenjaminHerbert/41f9964f0de18ddfdb776c4c802811fb to your computer and use it in GitHub Desktop.
Save BenjaminHerbert/41f9964f0de18ddfdb776c4c802811fb to your computer and use it in GitHub Desktop.
DSL in Groovy
class Behandlungsplan {
def count = 0
def patient(String yo) {
println "Patient: " + yo
}
def behandlung(String yolo) {
println yolo
count ++
}
def drucken() {
println count
}
static void create(Closure script) {
script.resolveStrategy = Closure.DELEGATE_FIRST
script.delegate = new Behandlungsplan()
script()
}
}
Behandlungsplan.create({
patient "wilhelm busch"
behandlung "motorschiene"
behandlung "fango"
behandlung "schlingentisch"
behandlung 2 mal "manuelle therapie"
drucken()
})
def plan = new Behandlungsplan()
plan.patient("wilhelm busch")
plan.behandlung("motoschiene")
plan.behandlung("fango")
plan.behandlung("schlingentisch")
plan.behandlung("manuelle therapie")
plan.drucken()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment