bookmarks/cheat/groovy.md

772 B

List class methods

<class>.metaClass.methods*.name.sort().unique()

Example

println new Person().metaClass.methods*.name.sort().unique()

Source http://groovy-almanac.org/list-the-methods-of-a-groovy-class/

Print all object properties

Method 1 (src)

println object.properties.sort{it.key}
.collect{it}
.findAll{!['class', 'active'].contains(it.key)}
.join('\n')

Method 2 (src)

object.properties.each { println "$it.key -> $it.value" }

Method 3 (src)

object.dump().println()