From: Martin Durai Date: 2007-11-21T19:25:41+09:00 Subject: Re: porting java methods to ruby Hi peter, i have attached my java code which i have to port to ruby. could you help me with this public char[] getTextCharacters(int [] holderForStartAndLength) { if( eventType == TEXT ) { if(usePC) { holderForStartAndLength[0] = pcStart; holderForStartAndLength[1] = pcEnd - pcStart; return pc; } else { holderForStartAndLength[0] = posStart; holderForStartAndLength[1] = posEnd - posStart; return buf; } } else if( eventType == START_TAG || eventType == END_TAG || eventType == CDSECT || eventType == COMMENT || eventType == ENTITY_REF || eventType == PROCESSING_INSTRUCTION || eventType == IGNORABLE_WHITESPACE || eventType == DOCDECL) { holderForStartAndLength[0] = posStart; holderForStartAndLength[1] = posEnd - posStart; return buf; } else if(eventType == START_DOCUMENT || eventType == END_DOCUMENT) { //throw new XmlPullParserException("no content available to read"); holderForStartAndLength[0] = holderForStartAndLength[1] = -1; return null; } else { throw new IllegalArgumentException("unknown text eventType: "+eventType); } // String s = getText(); // char[] cb = null; // if(s!= null) { // cb = s.toCharArray(); // holderForStartAndLength[0] = 0; // holderForStartAndLength[1] = s.length(); // } else { // } // return cb; } All these code comes unde java version of pull parser Robert Klemme wrote: > 2007/11/21, Peter Szinek : >> Hi, >> >> > public char[] getTextCharacters(int [] holderForStartAndLength) >> > { >> > } > > This won't even compile because there is no "return" statement. Also, > using an array to pass two values is at best sub optimal. And since > you do not provide any details about the class at hand nobody can > really help you. > >> > Could any one help me to do the same in ruby >> >> Oh sure! >> >> def getTextCharacters(holder_for_start_and_length) >> end > > LOL > > Actually, we can make this even *more* rubyish: > > def get_text_characters holder_for_start_and_length > end > > :-) > > Cheers > > robert -- Posted via http://www.ruby-forum.com/.