Possible Duplicate:
Why do this Ruby object have two to_s and inspect methods that do the same thing? Or, so it seems
In Ruby:
If x is some variable,
is there a difference between using x.inspect and using x.to_s?
What is the difference between the 2 methods?
They are usually but not always the same. According to the documentation for
Object.inspect():So by default, they return the same thing because
inspect()callsto_s(). Sometimes, however, it makes sense to overrideto_s()to do one thing, but when inspecting an object from irb, you want to see more details. So they can be set up to do different things.