From: "John Lam (CLR)" Date: 2007-07-16T09:47:18+09:00 Subject: What are the semantics of to_str? --_000_372109E149E8084D8E6C7D9CFD82E06329CEF23D5ENAEXMSGC115re_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Should to_str return an instance of String? Florian has an interesting test that demonstrates this behavior: it "returns nil if its argument does not respond to <=3D>" do obj =3D Object.new def obj.to_str() "" end ("abc" <=3D> obj).should =3D=3D nil end Right now my implementation of <=3D> calls to_str on obj and assumes that t= he result of that call is a String. Therefore, the correct result should be 1, not nil as in this example. It seems strange that Ruby would be calling <=3D> on obj and inverting the = result since I would assume that to_str would *convert* obj into a String. = Or is that not the case? If not, what are the semantics of to_str? Thanks, -John --_000_372109E149E8084D8E6C7D9CFD82E06329CEF23D5ENAEXMSGC115re_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Should to_str return an insta= nce of String?

 

Florian has an interesting test that demonstrates this= behavior:

 

  it "returns nil if its argument does not r= espond to <=3D>" do

    obj =3D Object.new

    def obj.to_str() "" end

   

    ("abc" <=3D> obj).s= hould =3D=3D nil

  end

 

Right now my implementation of <=3D> calls to_st= r on obj and assumes that the result of that call is a String.

 

Therefore, the correct result should be 1, not nil as = in this example.

 

It seems strange that Ruby would be calling <=3D>= ; on obj and inverting the result since I would assume that to_str would *convert= * obj into a String. Or is that not the case? If not, what are the semantics = of to_str?

 

Thanks,

-John

 

--_000_372109E149E8084D8E6C7D9CFD82E06329CEF23D5ENAEXMSGC115re_--