`taguri': undefined method `yaml_tag_subclasses?' .



 I am using the generally excellent hpricot library too do some XML parsing (saves writing boring, and error prone, regexes).  A piece of code which worked last week started failing today - not sure why as this was during a sanity-check test run to make sure I knew where I was up to.  That is, I hadn't changed anything since it last worked.  Not even so much as a foolish update of my ruby gems...

Anyway,  I have a bit of code which loads an "xml" file, tidies it up a bit, and then parses it.  I then select a specific child to work on:

     82 xml=File.read("ure.xml")

     83 xml.gsub!(/\s+/,' ')

     84 xml.gsub!(/> </,'><')

     85 doc=Hpricot::XML(xml)

     86 h=doc.children[1].children[1]

     87 h.each_child_with_index {|c,i|

And this is where the error in the title was happening, nested deep in a bunch of library calls.  Generally, I wouldn't recommend monkey patching, but in this case I am afraid I am more in need of the tiny app to run than to worry particularly about why the problem is suddenly happening.

Cure: edit lib/ruby/1.8/yaml/tag.rb 

     69                     #try checking whether it can actually respond to the call... PNP

     70                     if self.class.respond_to?(:yaml_tag_subclasses)

     71                       if self.class.yaml_tag_subclasses? and self.class != YAML::tagged_classes[tag]

     72                         tag = "\#{ tag }:\#{ self.class.yaml_tag_class_name }"

     73                       end

And voila, the problem goes away (I added the check to see whether the method exists before trying to call it).  I'm not directly using the tags, and I don't think that this impacts on the workings of hpricot in this instance. It seems to be letting my code run, anyway.

Trackback URL for this post:

http://brains.parslow.net/trackback/1623