Created
October 18, 2012 11:27
-
-
Save joeRinehart/3911192 to your computer and use it in GitHub Desktop.
Grails for the Wicked Smaht 1
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
| def outerVariable = "foo" | |
| def closure = { closureArgument -> | |
| println "$closureArgument $outerVariable" | |
| } | |
| (1..10).each{ i -> | |
| closure.call( i ) //prints "1 foo", "2 foo", etc. | |
| } |
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 Company { | |
| String name | |
| List people | |
| static hasMany = [ | |
| people : Person | |
| ] | |
| } |
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
| [1, 2, 3, 4].each{ i -> | |
| println i | |
| } |
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
| def company = new Company() | |
| def person = new Person() | |
| company.addToPeople( person ) | |
| company.removeFromPeople( person ) | |
| company.save() // cascades |
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
| def someList = ["One", "Two", "Three", "Four"] | |
| def someMap = [ keyOne : 1, keyTwo: 2 ] |
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 Person { | |
| String firstname | |
| String lastname | |
| Integer age | |
| } |
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
| println person.firstname | |
| println person[ "firstname" ] | |
| println person.getFirstname() |
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
| new Person( firstname: "John", lastname: "Doe", age: 12 ) |
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
| void setFirstname( String firstname ) { | |
| println "Setting firstname to ${firstname}" | |
| this.firstname = firstname | |
| } |
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 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