Overloading to_s in a class of my own

Moin!

Carl Youngblood wrote:

I’m confused by a problem I’m having trying to overload the to_s
operator so that my class will be accepted as a string where
applicable. Here’s a simplified version of the class:

You’re confusing #to_s with #to_str.

Thanks,
Carl

Regards,
Florian Gross

Moin!

Carl Youngblood wrote:

Creating to_str in my class still doesn’t work.

This works fine for me:

class Path
def initialize(path)
@path = path.to_s
end

def to_str
@path
end
end

Dir.mkdir(Path.new(“Hello World!”))

···

Regards,
Florian Gross