Tuesday, November 29, 2011

groovysh

Here are a few things I learned about groovysh: if you declare a variable like so:


def foobar = 5;

and then try to use foobar you get the following error:

groovy:000> def foobar = 5; ===> 5 groovy:000> print foobar; ERROR groovy.lang.MissingPropertyException: No such property: foobar for class: groovysh_evaluate at groovysh_evaluate.run (groovysh_evaluate:2) ... groovy:000>

It turns out that you must leave off the def. Then it works fine:
groovy:000> foobar = 5; ===> 5 groovy:000> print foobar; 5===> null groovy:000>


TAB Completion
You can type the first few letters after the . for a given object then press TAB. groovysh will display the possible options:
groovy:000> foobar.l
lastIndexOf(   leftShift(     length()

groovy:000> foobar.l

Type a few more characters, and the shell will complete the method name:

groovy:000> foobar.length()
===> 5
groovy:000>