I'm new to Ruby and I'm trying to understand this syntax so I can convert to Groovy. https://gist.github.com/brettporter/1723108
state = :body
and
conflict = {
:lineno => index + 1
}
and
conflict[:left_conflict]
Are state and conflict objects with body and lineno and left_conflict fields?? And if so how is the left_conflict field populated/assigned a value? Whats the equivalent way of doing this in Groovy
Those are symbols
in Ruby.
state = :body
Sets the variable state
to be the symbol :body
Groovy doesn't have symbols (see here) so a possible Groovy replacement for these is to just use Strings as the state and map keys like:
// Just use a String to maintain our state
state = 'body'
and
// Create a map
conflict = [ lineno: index + 1 ]
and
// get a value from a map
conflict[ 'left_conflict' ]
It's probably wise to put these magic strings into some sort of final static variable
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments