Groovy and Ruby are not much different, but the metaprogramming aspect is changing a bit.
Although I am not a Groovy expert, I can refer to some pointers in the documentation ( http://groovy.codehaus.org/Dynamic+Groovy ):
Dynamic method call:
an_instance.send("method_name")
// Groovy
anInstance."$methodName"()
Missing method:
# Ruby
def method_missing(meth, *args, &blk)
# Some code
end
def methodMissing(String name, args) {
}
Adding methods to the class at runtime:
# Ruby
class SomeObject
define_method :new_method do
# Do something
end
end
SomeObject.metaClass.newMethod = {->
}
source
share