From: David Vallner Date: 2006-11-08T11:00:35+09:00 Subject: Re: can you rubyfy this? --------------enigD446A2E8B75398E94827C994 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Jeff Pritchard wrote: > Boris Schulz wrote: >> Hi, >> >> I often read something about code being "rubystyle" though I am not >> exactly sure what it means. Maybe someone can help me out and put the >> couple of lines below into a typical ruby style? >> ... >> entrys.each{|node| >> file =3D node.elements["LOCATION"].attributes["DIR"] + >> node.elements["LOCATION"].attributes["FILE"] >> if File.exists?(file) >> tag =3D Tag.new(file) >> if !node.attributes["ARTIST"] >> node.add_element "ARTIST" >> end >> node.attributes["ARTIST"] =3D tag.artist >> end >> } >> out =3D File.new("test.xml", "w+") >> doc.write out >=20 > Hi Boris, > Main thing would be to replace the entrys.each { } construct with > entrys.each do |node| > stuff in here > end >=20 > Multi-line {} blocks are legal but not the "expected" way. The rest of= =20 > it looks ok to me. >=20 I claim subject to fashion / taste - I can't recall do/end being used much for blocks at all when I joined the list in the wild, wild days of 1.8.2 *duck* As for the OP's question, I'd parenthesise all method calls, spell "entries" correctly, and probably use a statement modifier unless instead of the one-line "if not". And personally, I'd also use file =3D node.elements.to_a('location/dir/node() | location/file/node()') out of sheer sadism to readers. Yay XPath golf. David Vallner --------------enigD446A2E8B75398E94827C994 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) iD8DBQFFUToyy6MhrS8astoRAu+jAJ92o4hePyTMUqt9rO8Iq7LLV9FoVwCfUWx6 YVZLD8KMitTcBZsCaAGToDM= =5kUH -----END PGP SIGNATURE----- --------------enigD446A2E8B75398E94827C994--