Created
June 1, 2016 10:41
-
-
Save vkoloss/accf1fd6b60c7cc0543bc6ca9b6a5221 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Basic DSL on Groovy for demo