From: "Anders Engström" Date: 2004-07-18T18:32:49+09:00 Subject: Re: REXML : add text to element without temp variable? --zYM0uCDKw75PZbzx Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Jul 18, 2004 at 12:09:25PM +0900, CD Baby wrote: > Say I'm trying to make this XML: > > Pink Floyd > Dark Side of the Moon > >=20 > Right now I'm doing this: > doc =3D Document.new > music =3D doc.add_element 'music' > artist =3D music.add_element 'artist' > artist.text =3D 'Pink Floyd' > album =3D music.add_element 'album' > album.text =3D 'Dark Side of the Moon' >=20 > QUESTION: > Why create variables for artist and album? > Shouldn't there be a way to add the text directly, without creating an > in-between (and never used again) variable? >=20 > Like this: > music.add_element('album').text =3D 'Dark Side of the Moon' >=20 > or this: > music.add_element('album').text << Text.new('Dark Side of the Moon') >=20 > Has anyone found a shortcut like this? >=20 doc =3D Document.new music =3D doc.add_element("music") music << Element.new("artist").add_text("Pink Floyd") music << Element.new("album").add_text("Dark side of the moon") //Anders --=20 =2E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . =2E Anders Engstr=F6m aengstrom@gnejs.net =2E http://www.gnejs.net PGP-Key: ED010E7F =2E [Your mind is like an umbrella. It doesn't work unless you open it.] = =20 --zYM0uCDKw75PZbzx Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFA+kOeuNLLbe0BDn8RAioLAJoClSDPSvFw/Tde4nIDZscscBOeQwCcDSp0 EETjDe4R+sch+XD4UyCjMb4= =e4H2 -----END PGP SIGNATURE----- --zYM0uCDKw75PZbzx--