Ah, although not completely, when trying to do what I’m trying to do
(basically a proxy class that wraps a string), I wind up getting a stack
overflow error from ruby. Oh well, I’ll play with it, might not be
possible (looks like much of String is compiled in C, not in ruby, which
makes it harder for me to reverse engineer/hack), but #to_str was the
right clue to go on.
I wondered why #to_str and #to_s both existed, but my stack overflow
error seems to suggest that in some cases one is defined in terms of the
other. I still wonder why they both exist.
Jonathan R. wrote:
Thanks, that helps a lot, actually!
Stefano C. wrote:
Alle Tuesday 18 November 2008, Jonathan R. ha scritto:
Is there anything I can do so my class will always be converted properly
to a String by ruby, in all cases, so client code can really use it just
like a string?
Defining a to_str method makes String#+ work, but I’m not sure it’ll
everywhere. According to some documentation I found on google, defining
method should make the class usable in place of a string. Note, however,
you still have to define a to_s method if you want to change the output
I hope this helps