I am working under some DSL using Groovy categories and I would like to find a way to use my DSL with groovy shell without explicitly writing use(MyCategory){ myObject.doSomething() }
for each command.
For example, suppose I have the following toy category:
class MyCategory {
static Integer plus(Integer integer, String string){
return integer + Integer.valueOf(string)
}
}
Then, I can use this category in groovysh
in the following way:
groovy> use(MyCategory){ 2 + '3' } //gives 5
So, is there any way to set up MyCategory
globally for all groovysh
commands, so it will not be necessary to each time wrap my commands in use(MyCategory) { ... }
? For example:
groovy> useGlobally(MyCategory); //call something like this only once
groovy> 2 + '3' //automatically uses MyCategory and gives 5