Created
October 11, 2010 02:43
-
-
Save toby55kij/619889 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
// g100pon #66 Expando使用例 | |
//テスト用メソッド | |
def testMethod(person) { | |
//引数personにはプロパティfirstName,familyNameとname()メソッドがあることを前提としている | |
assert person.name() == "${person.firstName} ${person.familyName}" | |
} | |
//Expandoを作成 | |
def person = new Expando() | |
//プロパティを追加 | |
person.firstName = 'John' | |
person.familyName = 'Smith' | |
//メソッドとしてクロージャを追加 | |
person.name = {"$firstName $familyName"} | |
//テスト用メソッドを実行 | |
testMethod person //テストに成功 | |
//プロパティを変更 | |
person.firstName = 'Kyle' | |
//テストを再実行 | |
testMethod person //テストに成功 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment