Skip to content

Tag attribute shortcuts always change scope #1041

@pguillory

Description

@pguillory

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions