Return type

Actually the following code is a java return type. could any one help to
do the same in ruby.

 return processNamespaces ? elUri[depth] : NO_NAMESPACE

Thank you in advance

On Nov 21, 4:11 am, Martin D. [email protected] wrote:

Actually the following code is a java return type. could any one help to
do the same in ruby.

 return processNamespaces ? elUri[depth] : NO_NAMESPACE

I don’t understand your question.

hi gavin

Iam in a task of porting java class into ruby. so how to port the
following java code into ruby. I didnt understood exactly what java does
with the following code. so could you help me to port this one.

            public String getNamespace()
      {
    if(eventType == START_TAG) {
        return processNamespaces ? elUri[ depth  ] : NO_NAMESPACE;
    } else if(eventType == END_TAG) {
        return processNamespaces ? elUri[ depth ] : NO_NAMESPACE;
    }
    return null;
   }

Gavin K. wrote:

On Nov 21, 4:11 am, Martin D. [email protected] wrote:

Actually the following code is a java return type. could any one help to
do the same in ruby.

 return processNamespaces ? elUri[depth] : NO_NAMESPACE

I don’t understand your question.

Thank you Gavin your answers really helped me to code well

On Nov 22, 1:47 am, Martin D. [email protected] wrote:

    } else if(eventType == END_TAG) {
        return processNamespaces ? elUri[ depth ] : NO_NAMESPACE;
    }
    return null;
   }

It seems that you don’t know what the Java code is doing, and you
don’t know how to program in Ruby. I would say you have a lot of work
ahead of you.

Are eventType and processNamespaces and elUri and depth all global
variables? Let’s assume so.

The following is valid Ruby code, if you have defined the appropriate
constants:

def getNamespace
if $eventType == START_TAG
return $processNamespaces ? $elUri[ $depth ] : NO_NAMESPACE
elsif $eventType == END_TAG
return $processNamespaces ? $elUri[ $depth ] : NO_NAMESPACE
else
return nil
end
end

If you don’t understand the “a ? b : c” syntax, google for “ternary
operator”.

Here is the same code as the above written in increasingly simpler
ways:

def getNamespace
if $eventType == START_TAG || $eventType == END_TAG
return $processNamespaces ? $elUri[ $depth ] : NO_NAMESPACE
else
return nil
end
end

def getNamespace
if $eventType == START_TAG || $eventType == END_TAG
$processNamespaces ? $elUri[ $depth ] : NO_NAMESPACE
else
nil
end
end

def getNamespace
if $eventType == START_TAG || $eventType == END_TAG
$processNamespaces ? $elUri[ $depth ] : NO_NAMESPACE
end
end

def getNamespace
case $eventType
when START_TAG, END_TAG
$processNamespaces ? $elUri[ $depth ] : NO_NAMESPACE
end
end

def getNamespace
if [ START_TAG, END_TAG ].include?( $eventType )
$processNamespaces ? $elUri[ $depth ] : NO_NAMESPACE
end
end

Gavin K. wrote:

def getNamespace
if [ START_TAG, END_TAG ].include?( $eventType )
$processNamespaces ? $elUri[ $depth ] : NO_NAMESPACE
end
end

And of course, the oneliner:

def getNamespace
[ START_TAG, END_TAG ].include?( $eventType ) &&
($processNamespaces ? $elUri[$depth] : NO_NAMESPACE)
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs