Hi! I''m trying to parse a XML document (MusicXML), I found that here something about it: http://railstips.org/blog/archives/2008/08/11/parsing-xml-with-ruby/ - I chose Hpricot, but I have a problem: in XML document, which I''m trying to parse, there are names of blocks with minus sign, for example <score-partwise>. In Hpricot it should looks something like this: xml = File.read(path) puts Benchmark.measure { doc = Hpricot::XML(xml) (doc/:score-partwise).each do |s| # here we have s as each score-partwise block end } But it throws undefined local variable or method `partwise'' for #<MusicxmlController:0xb6badff4>, becouse in symbols names minus sign is prohibited. How can I make a symbol name with minus sign? cheers, simon -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 19 Jul 2010, at 11:37, Szymon Przybył wrote:> xml = File.read(path) > puts Benchmark.measure { > doc = Hpricot::XML(xml) > (doc/:score-partwise).each do |s| > # here we have s as each score-partwise block > end > } > > But it throws undefined local variable or method `partwise'' for > #<MusicxmlController:0xb6badff4>, becouse in symbols names minus sign > is prohibited. How can I make a symbol name with minus sign?Just use a string instead: (doc/''score-partwise'') Best regards Peter De Berdt -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Szymon Przybył wrote: [...]> But it throws undefined local variable or method `partwise'' for > #<MusicxmlController:0xb6badff4>, becouse in symbols names minus sign > is prohibited. How can I make a symbol name with minus sign?Well, you can actually have any characters you like in a symbol name. The :name syntax only works if the symbol name doesn''t contain "weird" characters, but the following syntaxes will work regardless: :''name-with-weird-characters'' :"name-with-weird-characters-and-#{variable_interpolation}" ...or just use String#to_sym . We are now well out of Rails territory and into basic Ruby, so further discussion probably should go to the main Ruby list.> > cheers, > simonBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.