/ Published in: Groovy
A nice example of utilizing Groovy closures in order to create a when statement in Groovy (http://www.transentia.com.au/flatpress/?x=entry:entry090311-222726).
Expand |
Embed | Plain Text
when "Focus", "Ford" when "Navigator", "Lincoln" when "Camry", "Toyota" when "Civic", "Honda" when "Patriot", "Jeep" when "Jetta", "VW" when "Ceyene", "Porsche" when "Outback", "Subaru" when "520i", "BMW" when "Tundra", "Nissan" otherwise "Unknown" } println "The $car is made by $manufacturer" closure.subject = obj closure.when = { value, result -> } closure.resolveStrategy = Closure.DELEGATE_FIRST try { closure() closure.otherwise() r.result } } def result }
You need to login to post a comment.
