Skip to content

Instantly share code, notes, and snippets.

@nbqx
Created October 10, 2010 15:54
Show Gist options
  • Save nbqx/619342 to your computer and use it in GitHub Desktop.
Save nbqx/619342 to your computer and use it in GitHub Desktop.
// g100pon #69 動的なメソッド追加
class MyClass{
def say = {
println "g100pon!!"
}
}
def cls = new MyClass()
cls.say()
cls.metaClass.define{
sayTwice{ 2.times{say()} }
"3度言う"{ 3.times{say()} }
}
cls.sayTwice()
cls."3度言う"()
cls.metaClass."そこまで言う" << { println "これでもいいんだよ" }
cls."そこまで言う"()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment