For some testing, I'm looking for a Ruby built-in class or module (other than String) that has method #to_str.
(I know that many have method #to_s, but that's not what I'm looking for.)
I've pored over the docs, and can't find any such.
The easiest way is to ask Ruby herself:
ObjectSpace.
each_object(Module).
select {|mod| mod.instance_methods(false).include?(:to_str) } -
[String]
#=> [NameError::message]
So, it turns out the only other class that defines to_str
is an internal implementation class inside NameError
. Which makes sense, really, there are not that many objects in Ruby that are strings but are not instances of String
.
I would expect a Ropes library (if such a thing exists) to implement to_str
, for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With