From: Konrad Meyer Date: 2007-10-11T12:25:34+09:00 Subject: Re: what does print call internally? --nextPart1742221.jO4t3LgaTi Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Quoth Joel VanderWerf: > Eric Hodel wrote: > > On Oct 10, 2007, at 15:31 , Martin DeMello wrote: > >=20 > >> irb(main):001:0> puts nil > >> nil > >> =3D> nil > >> irb(main):002:0> print nil > >> nil=3D> nil > >> irb(main):003:0> class NilClass > >> irb(main):004:1> def inspect > >> irb(main):005:2> "foo" > >> irb(main):006:2> end > >> irb(main):007:1> end > >> =3D> foo > >=20 > > it calls #to_s. >=20 > Hm. What's going on here then: >=20 > $ ruby -e 'p nil.to_s' > "" > $ ruby -e 'print nil' > nil >=20 > --=20 > vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407 Irb calls NilClass#inspect, as the OP demonstrated. irb(main):001:0> class NilClass; def inspect() "foo" end; end # =3D> foo irb(main):002:0> nil # =3D> foo irb(main):003:0> puts nil # =3D> foo nil I'm guessing puts/print treat nil as a special case, but I may be wrong. =2D-=20 Konrad Meyer http://konrad.sobertillnoon.com/ --nextPart1742221.jO4t3LgaTi Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQBHDZekCHB0oCiR2cwRAoIiAJ4zDtSb9Vkz1s0O4fASSQ7cDQnyHACgznWs oVfN+75m30PrtFH2tlbGIHo= =5nKb -----END PGP SIGNATURE----- --nextPart1742221.jO4t3LgaTi--