E
EdUarDo
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.
What's the correct syntax?
I know I could do:
def to_s
s = "\n#{@post}"
if @post != :GK
s += "#{@side}"
end
s
end
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.
What's the correct syntax?
I know I could do:
def to_s
s = "\n#{@post}"
if @post != :GK
s += "#{@side}"
end
s
end