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>

Monday, September 05, 2011

Groovy and its bad moods

I had not picked up Groovy in a while. So I downloaded Groovy 1.8.1 and off I went with HelloWorld.
class Greet {
def name
Greet(who) { name = who[0].toUpperCase() +
who[1..-1] }
def salute() { println "Hello $name!" }
}

g = new Greet('world') // create object
g.salute()

Then I compiled it in the GroovyConsole and I got the following error:
Invalid duplicate class definition of class Greet : The source Greet.groovy contains at least two definitions of the class Greet.


What da!?
It turns out that the Groovy compiler tries to put the code that is outside the class into a .class file called Greet.class Ooops! So the quick fix is to save the file as a different name such as Foo.groovy. Then after the Groovy compiler runs, you will end you with Foo.class and Greet.class

Now you know.

Tuesday, April 05, 2011

VirtualBox and Ubuntu

I just installed VirtualBox. Pretty coool! Then I created a VDI and installed Ubuntu 10.10. I might uninstall it and just install an instance of headless Fedora.