views:

23

answers:

3

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
@rlovtang answered the question above
sbglasius
A: 

You can do that using metaprogramming:

MyClass.metaClass.aliasMethod = MyClass.metaClass.originalMethod
Michael Borgwardt
+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