expandometaclass

shortcut for creating a Map from a List in groovy?

I'd like some sorthand for this: Map rowToMap(row) { def rowMap = [:]; row.columns.each{ rowMap[it.name] = it.val } return rowMap; } given the way the GDK stuff is, I'd expect to be able to do something like: Map rowToMap(row) { row.columns.collectMap{ [it.name,it.val] } } but I haven't seen anything in the docs... ...

Groovy expando metaclass

Hi, I've developed a Class that has some methods that augment Integer, it mainly lets me do this: def total = 100.dollars + 50.euros Now I have to extend Integer.metaClass doing something like this: Integer.metaClass.getDollars = {-> Money.Dollar(delegate) } I tried putting that at the bottom of the file, before the Money class...

Grails behavior difference between run-app and run-war

I'm relatively new to Groovy and Grails and am trying them out in my spare time. I've got a small test Grails application that I'm able to run fine using grails run-app, but grails run-war results in an error. In the grails-app/conf/BootStrip.init method, I'm adding some property getters onto the DefaultGrailsControllerClass and Defaul...

How to add a new closure to a class in groovy.

From Snipplr Ok here is the script code, in the comments is the question and the exception thrown class Class1 { def closure = { println this.class.name println delegate.class.name def nestedClos = { println owner.class.name } nestedClos() } } def clos = new Class1().closure ...