|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Actually the following code is a java return type. could any one to
do the same in ruby. return processNamespaces ? elUri[depth] : NO_NAMESPACE Thank you in advance -- Posted via http://www.ruby-forum.com/. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Nov 21, 4:11 am, Martin Durai <mar...@angleritech.com> wrote:
> Actually the following code is a java return type. could any one to > do the same in ruby. > > return processNamespaces ? elUri[depth] : NO_NAMESPACE I don't understand your question. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 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 Kistner wrote: > On Nov 21, 4:11 am, Martin Durai <mar...@angleritech.com> wrote: >> Actually the following code is a java return type. could any one to >> do the same in ruby. >> >> return processNamespaces ? elUri[depth] : NO_NAMESPACE > > I don't understand your question. -- Posted via http://www.ruby-forum.com/. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Nov 22, 1:47 am, Martin Durai <mar...@angleritech.com> wrote:
> 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 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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Gavin Kistner 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 -- Posted via http://www.ruby-forum.com/. |
|
![]() |
| Outils de la discussion | |
|
|