Ruby for Groovy

I have a framework written in Ruby that needs to be converted to Groovy.
It does not use anything outside the main ruby, but many metaprograms.

Are all the core features supported by Groovy and the complexity of the replacement complex?

+3
source share
2 answers

Groovy and Ruby are not much different, but the metaprogramming aspect is changing a bit.

Although I am not a Groovy expert, I can refer to some pointers in the documentation ( http://groovy.codehaus.org/Dynamic+Groovy ):

Dynamic method call:

# Ruby
an_instance.send("method_name")

// Groovy
anInstance."$methodName"()

Missing method:

# Ruby
def method_missing(meth, *args, &blk)
  # Some code
end

// Groovy
def methodMissing(String name, args) {
  // Some code
}

Adding methods to the class at runtime:

# Ruby
class SomeObject
  define_method :new_method do
    # Do something
  end
end

// Groovy
SomeObject.metaClass.newMethod = {->
  // Do something
}
+8
source

, ( , ..), , . , , , .

Groovy? JVM (, /), JRuby? .

+5

Source: https://habr.com/ru/post/1712084/


All Articles