From: "David A. Black" Date: 2005-07-26T00:24:00+09:00 Subject: Re: Newby question 'unless' Hi -- On Tue, 26 Jul 2005, EdUarDo wrote: > Hi all, I'm overriding to_s method and I want to > print an attribute if a condition is fulfilled. > > def to_s > "#{@a}" + "#{@b}" unless @a == 0 > end > > That sentence doesn't print anything when @a == 0 but what I want to do > is to not print @b when @a == 0. If it doesn't print anything then presumably it's not printing @b. Or did you mean that last @a to be @b? If so, you could do: def to_s "#{@a unless @a.zero?}#{@b unless @b.zero?}" end David -- David A. Black dblack@wobblini.net