Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag attribute shortcuts always change scope #1041

Closed
pguillory opened this issue Feb 3, 2014 · 2 comments · Fixed by #3267
Closed

Tag attribute shortcuts always change scope #1041

pguillory opened this issue Feb 3, 2014 · 2 comments · Fixed by #3267
Labels
topic/builder XML::Builder behaviors
Milestone

Comments

@pguillory
Copy link

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>
@flavorjones flavorjones added the topic/builder XML::Builder behaviors label Jan 3, 2022
@flavorjones
Copy link
Member

Reproduced with main @ 238bc49

@flavorjones
Copy link
Member

Proposed fix in #3267, thanks for your patience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic/builder XML::Builder behaviors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants