groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yaro <y...@mail.ru>
Subject Re: Bypassing local variables in a closure
Date Sat, 18 Jul 2015 02:05:40 GMT
interestingly, I managed to do it through some obscure way:
in someMethod:

closure.class.declaredFields*.name.findAll { it ==~ /^[^_$].+/ }.each {
      actions.@"$it"= new Reference(&myValidatorMethod)
    }

which finds all local variables within the closure and changes their binding 
to my validator method, so any calls that match the local variables names
will get handled by validator and anything else - by methodMissing.

Anybody can suggest a better solution?



--
View this message in context: http://groovy.329449.n5.nabble.com/Bypassing-local-variables-in-a-closure-tp5726326p5726327.html
Sent from the Groovy Users mailing list archive at Nabble.com.

Mime
View raw message