I have a framework written in Ruby that needs to be converted into Groovy.
It does not use anything outside of core ruby, but a lot of meta programming.
Are all the same basic features supported by Groovy and is the changeover complicated?
I have a framework written in Ruby that needs to be converted into Groovy.
It does not use anything outside of core ruby, but a lot of meta programming.
Are all the same basic features supported by Groovy and is the changeover complicated?
I suspect it might not be easy (depending on size, functionality etc.), and it's not so much of a translation as a rewrite. Whenever I find myself thinking of doing a rewrite, I refer myself to Joel's musings on this before going any further.
Why do you need to rework this in Groovy ? If you need the JVM (say, to integrate additional libraries/frameworks), have you looked at JRuby ? It might save you a lot of work and pain.
Groovy and Ruby are not terribly different, but the metaprogramming aspect changes a bit.
Although I am not a Groovy expert, I can refer to you some pointers in the documentation (http://groovy.codehaus.org/Dynamic+Groovy):
Dynamic method calling:
# Ruby
an_instance.send("method_name")
// Groovy
anInstance."$methodName"()
Method missing:
# Ruby
def method_missing(meth, *args, &blk)
# Some code
end
// Groovy
def methodMissing(String name, args) {
// Some code
}
Adding methods to a class at runtime:
# Ruby
class SomeObject
define_method :new_method do
# Do something
end
end
// Groovy
SomeObject.metaClass.newMethod = {->
// Do something
}