class Foo
def to_s(type : Symbol)
String.build do |sb|
to_s(sb, type)
end
end
def to_s(io : IO, type : Symbol? = nil) : Nil
case type
when :abc
io << "abc"
when :xyz
io << "xyz"
else
# normal
io << "hello"
end
end
end
f = Foo.new
pp f.to_s # => "hello"
pp f.to_s(:xyz) # => "xyz"
f.to_s(STDOUT, :abc) # => abc
Suggestion: when you say that something doesn’t work as you expected, please show what you expected in addition to the actual behavior. To me the output you showed is what I’d expect.