Created
January 24, 2014 15:22
-
-
Save kaakaa/8599348 to your computer and use it in GitHub Desktop.
This file contains 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
def dsl = ''' | |
person.is { | |
name 'taro' | |
age '28' | |
}.say() | |
''' | |
def impl = ''' | |
def getPerson(){ | |
new Person() | |
} | |
class Person{ | |
def Person(){ | |
def mc = new ExpandoMetaClass( Person, false, true) | |
mc.initialize() | |
this.metaClass = mc | |
} | |
def is(Closure closure){ | |
closure.delegate = this | |
closure() | |
return this | |
} | |
def methodMissing(String name, args){ | |
this.metaClass."${name}" = args[0] | |
} | |
def say(){ | |
println "I am ${this.name}. ${this.age} old." | |
} | |
} | |
''' | |
def script = """ | |
${dsl} | |
${impl} | |
""" | |
new GroovyShell().evaluate(script) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am taro. 28 old.