return type

M

Martin Durai

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
 
P

Phrogz

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.
 
M

Martin Durai

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 said:
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.
 
P

Phrogz

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;
}

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
 
J

Juan Ayup

Gavin said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,290
Messages
2,571,453
Members
48,131
Latest member
AntoniaSep

Latest Threads

Top