Last active
August 29, 2015 14:06
-
-
Save melix/5bc7c5db7ab986924181 to your computer and use it in GitHub Desktop.
Fat fingers correction in Groovy
This file contains hidden or 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
import org.codehaus.groovy.reflection.ClassInfo | |
import org.codehaus.groovy.runtime.MethodRankHelper | |
trait FatFingers { | |
def methodMissing(String name, args) { | |
def ci = ClassInfo.getClassInfo(this.class) | |
def methods = [*ci.metaClass.methods,*ci.metaClass.metaMethods] | |
def sugg = MethodRankHelper.rankMethods(name,args,methods) | |
if (sugg) { | |
sugg[0].invoke(this, args) | |
} else { | |
super.methodMissing(name, args) | |
} | |
} | |
} | |
class Boo implements FatFingers { | |
void boo() { println "Boo" } | |
} | |
def b = new Boo() | |
b.booo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/timyates/groovy-tpyo ;-)