From: akbarhome Date: 2007-06-22T19:05:11+09:00 Subject: Re: avoiding nil.methodcalls short and cheap On Jun 22, 4:53 pm, Thorsten Rossner wrote: > Hi, > > I often have to check if a methodcall A is not returning nil before > calling another method on the return value of the methodcall A. I'm > looking for a short and cheap (avoiding to call method A two times like > in this example where xmltag.get_text is method A: > textvalue = xmltag.get_text.value if xmltag.get_text > ) > The ideal solution would be a oneliner with only little complexity > calling method A just one time. Am I using the wrong approach here > anyway? > > Thanks, > tr! > > -- > Posted viahttp://www.ruby-forum.com/. Consider this: begin textvalue = xmltag.get_text.value rescue NoMethodError end