From: Trans Date: 2006-11-08T11:15:10+09:00 Subject: Re: can you rubyfy this? 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? Looks good. Just some small touchups. One thing to point out: Some prefer to use call paraenteticals as little as possible. Other's, like myself, prefer to use them in most cases. #!/usr/bin/ruby require "rexml/document" require "id3lib" include REXML include ID3Lib doc = Document.new(File.new("collection.nml")) entrys = doc.elements.to_a("//ENTRY") entrys.each do |node| loc = node.elements["LOCATION"] file = loc.attributes["DIR"] + loc.attributes["FILE"] if File.exist?(file) # no plural tag = Tag.new(file) unless node.attributes["ARTIST"] node.add_element "ARTIST" end node.attributes["ARTIST"] = tag.artist end end out = File.new("test.xml", "w+") doc.write(out) T.