Nokogiri::XML::Builder::NodeBuilder#method_missing always calls its block with instance_eval, changing the scope. This behavior is surprising. I would have expected these two ways of adding a class to an element to be equivalent.
puts Nokogiri::XML::Builder.new { |doc|
doc.root {
doc.div(:class => 'foo') { doc.text self.class }
doc.div.foo { doc.text self.class }
}
}.to_xml
<?xml version="1.0"?>
<root>
<div class="foo">Object</div>
<div class="foo">Nokogiri::XML::Builder</div>
</root>
Nokogiri::XML::Builder::NodeBuilder#method_missing always calls its block with instance_eval, changing the scope. This behavior is surprising. I would have expected these two ways of adding a class to an element to be equivalent.