Skip to content

Conversation

@nobu
Copy link
Member

@nobu nobu commented Sep 18, 2025

new_toplevel does not define new variables that is not defined already in the binding.

require 'erb'
e = ERB.new("")
b = e.send(:new_toplevel, [:x])
p b.local_variable_get(:x) #=> NameError, local variable 'x' is not defined

Conversely, hides the variables that have already been defined.

require 'erb'
e = ERB.new("")
b = e.send(:new_toplevel, [])
p b.local_variable_get(:b) == b #=> true
b = e.send(:new_toplevel, [:b])
p b.local_variable_get(:b)      #=> nil

@nobu nobu requested a review from BurdetteLamar September 18, 2025 03:19
@k0kubun k0kubun merged commit de0f185 into ruby:master Sep 18, 2025
8 checks passed
@BurdetteLamar
Copy link
Member

@nobu, I'm not sure what to do here. Certainly I approve your change.

@nobu nobu deleted the doc-new_toplevel branch September 18, 2025 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants