From: David Vallner Date: 2006-11-14T07:20:01+09:00 Subject: Re: undefined method `string' --------------enigAC8A3F61AE5E75E9D6E52355 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Comfort Eagle wrote: > Why does this work: >=20 > require 'rubygems' > require 'rubyful_soup' >=20 > sourceFile =3D 'lists.php' > desFile =3D 'parsedtext.txt' >=20 >=20 > open(sourceFile).each { |x| > soup =3D BeautifulSoup.new(x) > puts soup.a > } >=20 > but adding .string a la: >=20 > require 'rubygems' > require 'rubyful_soup' >=20 > sourceFile =3D 'lists.php' > desFile =3D 'parsedtext.txt' >=20 >=20 > open(sourceFile).each { |x| > soup =3D BeautifulSoup.new(x) > puts soup.a.string > } >=20 > results in: > undefined method `string' for nil:NilClass (NoMethodError) ?? >=20 Because soup.a is nil? As the interpreter obediently informs you of. "puts soup.a" works because to_s is defined on nil to return the empty string. David Vallner --------------enigAC8A3F61AE5E75E9D6E52355 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (MingW32) iD8DBQFFWO+Ky6MhrS8astoRApNCAJ4ufiNLIT4ySnTPS3U83jWjHUpU+wCdG++D dJckgHnYF/gnhU731PhnGlQ= =AMfK -----END PGP SIGNATURE----- --------------enigAC8A3F61AE5E75E9D6E52355--