C
Carl Youngblood
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:
class Path
def initialize(pathstring)
@pathstring = pathstring
end
def to_s
@pathstring
end
end
It seems to work when I pass an instance to puts or something like
that. Why won't it work when I do something like this:
p = Path.new("somepath")
Dir.mkdir(p)
I get the following error message:
test.rb:4:in `mkdir': wrong argument type Path (expected String)
(TypeError)
from test.rb:4
Thanks,
Carl
operator so that my class will be accepted as a string where
applicable. Here's a simplified version of the class:
class Path
def initialize(pathstring)
@pathstring = pathstring
end
def to_s
@pathstring
end
end
It seems to work when I pass an instance to puts or something like
that. Why won't it work when I do something like this:
p = Path.new("somepath")
Dir.mkdir(p)
I get the following error message:
test.rb:4:in `mkdir': wrong argument type Path (expected String)
(TypeError)
from test.rb:4
Thanks,
Carl