Skip to content

Instantly share code, notes, and snippets.

@joeRinehart
Created October 18, 2012 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joeRinehart/3911192 to your computer and use it in GitHub Desktop.
Save joeRinehart/3911192 to your computer and use it in GitHub Desktop.
Grails for the Wicked Smaht 1
def outerVariable = "foo"
def closure = { closureArgument ->
println "$closureArgument $outerVariable"
}
(1..10).each{ i ->
closure.call( i ) //prints "1 foo", "2 foo", etc.
}
class Company {
String name
List people
static hasMany = [
people : Person
]
}
[1, 2, 3, 4].each{ i ->
println i
}
def company = new Company()
def person = new Person()
company.addToPeople( person )
company.removeFromPeople( person )
company.save() // cascades
def someList = ["One", "Two", "Three", "Four"]
def someMap = [ keyOne : 1, keyTwo: 2 ]
class Person {
String firstname
String lastname
Integer age
}
println person.firstname
println person[ "firstname" ]
println person.getFirstname()
new Person( firstname: "John", lastname: "Doe", age: 12 )
void setFirstname( String firstname ) {
println "Setting firstname to ${firstname}"
this.firstname = firstname
}
class Person {
String firstname
String lastname
Integer age
Company company
static belongsTo = [
company : Company
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment