From: Eric Hodel Date: 2003-02-04T07:56:23+09:00 Subject: Re: Designing API strings vs symbols? --jZNlLGxhPb4urluq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Tom Sawyer (transami@transami.net) wrote: > On Monday 03 February 2003 03:35 pm, Travis Whitton wrote: > > Would most people prefer profile to exclusively use symbols, or should = it > > use the mix of symbols and strings as defined above? I.e., >=20 > i have considered this myself and i think the best answer is to support w= hat=20 > the application demands. in other words. if spaces and such are illegal f= or=20 > your apps use, then use Symbol, if not then use String. if you mix then y= ou=20 > have potential for errors. 'foo bar baz'.intern # =3D> :foo bar baz > of course if you internally support string, symbols are a subset of strin= gs.=20 > so you could do #to_s on everything that comes in and effectively take th= em=20 > into account, but do not go the other way if there is any potential=20 > uncertainty. =46rom a black-box perspective, a Symbol cannot contain \0, but everything else seems cool. irb(main):001:0> File.open('/kernel') { |fp| puts fp.read.intern.class } ArgumentError: string contains `\0' from (irb):1:in `intern' from (irb):1 from (irb):1:in `open' from (irb):1 irb(main):002:0> File.open('/kernel') { |fp| puts fp.read.gsub("\0", '').in= tern.class } Symbol =3D> nil --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --jZNlLGxhPb4urluq Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.0 (FreeBSD) iD8DBQE+PvOUMypVHHlsnwQRAhk+AKDG1rNCz8HRur651KX/BasbMwta4wCfcCYu r4LNUQHNjfqRjDkEi/ULRow= =yYWW -----END PGP SIGNATURE----- --jZNlLGxhPb4urluq--