groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yaro <y...@mail.ru>
Subject Bypassing local variables in a closure
Date Sat, 18 Jul 2015 00:53:36 GMT
Hi, all!

When I execute closure.call(), I get an error: No signature of method:
java.lang.Integer.call() for arg types LinkedHashMap.
Rightly so, because local variables are looked up before the delegate and
user (which value is int
 5) is enclosed by the closure.

How do I bypass local variables and go straight to delegate?   
Perhaps add invokeMethod or getProperty to closure's metaClass?

class SomeClass {

 def controllerAction() {
    def user = service.currentUser // = 5
  
    someMethod {
      user exists: true
     }
  }

 def someMethod(Closure closure)  {
    closure.delegate = new SomeDelegate()
    closure.resolveStrategy = Closure.DELEGATE_ONLY
    closure.call()
  }
}



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

Mime
View raw message