From: dblack@... Date: 2003-01-17T10:25:07+09:00 Subject: Re: quick: it responds, it evaluates, and is not empty Hi -- On Fri, 17 Jan 2003, ahoward wrote: > On Fri, 17 Jan 2003, Tom Sawyer wrote: > > > quick quest: anyone know of a nice slick short and sweet way to do this: > > > > if self.respond_to?(:ameth) > > if ameth > > if not ameth.to_s.empty? > > ... > > end > > end > > end > > i'm assuming :ameth and ameth are meant to be a Symbol and String > respectively, otherwise the 2nd and 3rd calls would be meaningless since the > call to respond_to? would have failed so > > respond_to? :ameth and ameth and not ameth.to_s.empty? ... > > short ciruits the same way. not that short... but potentially one line. > > it's hard to envision why simply > > ... if respond_to ameth > > would not suffice though? why have :ameth and ameth? Because if you just have respond_to?(ameth), then ameth will be evaluated (method call or local variable), which probably isn't what's wanted. irb(main):005:0> "".respond_to?(:blah) false irb(main):006:0> "".respond_to?(blah) NameError: undefined local variable or method `blah' for # from (irb):6 David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav