when does the object execute respond_to? :to_str respond_to? :to_str , you expect it to actually act as a String . This means that it must implement all String methods, so you can potentially interrupt some code by relying on it.
to_s means you get a string representation of your object, so many objects implement it, but the string you get is far from being “semantically” equivalent to your object (an_hash.to_s is far from Hash ). :symbol.to_str absence reflects this: the symbol should NOT and should NOT be confused with a string in Ruby, because they serve completely different purposes.
You would not think about adding to_str to Int, right? However, Int has a lot to do with the symbol: each one is unique. When you have a symbol, you expect it to be unique and unchanging.
source share