Skip to content

Instantly share code, notes, and snippets.

@melix
Last active August 29, 2015 14:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melix/5bc7c5db7ab986924181 to your computer and use it in GitHub Desktop.
Save melix/5bc7c5db7ab986924181 to your computer and use it in GitHub Desktop.
Fat fingers correction in Groovy
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()
@timyates
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment