From: dblack@... Date: 2007-08-15T09:57:33+09:00 Subject: Re: to_str behavior Hi -- On Wed, 15 Aug 2007, Steven Lumos wrote: > dblack@rubypal.com writes: >> static VALUE >> rb_str_equal(str1, str2) >> VALUE str1, str2; >> { >> if (str1 == str2) return Qtrue; >> if (TYPE(str2) != T_STRING) { >> if (!rb_respond_to(str2, rb_intern("to_str"))) { >> return Qfalse; >> } >> return rb_equal(str2, str1); >> } >> >> if (RSTRING(str1)->len == RSTRING(str2)->len && >> rb_str_cmp(str1, str2) == 0) { >> return Qtrue; >> } >> return Qfalse; >> } >> >> I haven't quite figured out what the point is of testing to see >> whether str2 responds to "to_str", since even if it does, to_str isn't >> called. But I might just have to keep following the trail.... > > Note the order of arguments. It means str2#== will be used instead of > String#==. Interesting. I'm not sure what the point of the to_str test is, though, since to_str doesn't actually seem to get called. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)