Hi, I am trying to redefine dynamic methods of a domain in groovy. Is there something similar alias method in ruby in groovy?
A:
I haven't seen this in Groovy and cannot find anything about it.
One way to achieve it would be the obvious but poor way.
def greet(name) {
println "Hello $name"
}
def sayHello(name) {
greet(name)
}
Flash84x
2010-10-26 05:38:19
@rlovtang answered the question above
sbglasius
2010-10-26 07:40:14
A:
You can do that using metaprogramming:
MyClass.metaClass.aliasMethod = MyClass.metaClass.originalMethod
Michael Borgwardt
2010-10-26 05:44:56
+2
A:
Do you mean like the method reference operator .&
?
def out = System.out.&println
out << "Hello"
and
def greet(name) {
println "Hello $name"
}
def sayHello = this.&greet
sayHello "Ronny"
It is mentioned at http://groovy.codehaus.org/Operators but an example is missing
rlovtang
2010-10-26 05:51:26