It doesn't equal the binding
at the main thread, what is this toplevel scope? What does this scope differ from the binding
at the main thread?
> ruby -e 'puts TOPLEVEL_BINDING === binding'
false
The fact is, TOPLEVEL_BINDING
always refers to a predefined global instance of Binding
, while Kernel#binding
creates a new instance of Binding
that encapsulates the current execution context every time. At top level, they both contain the same bindings, but they are not the same object and you cannot test their binding equality with ==
or ===
.
puts TOPLEVEL_BINDING
puts TOPLEVEL_BINDING
puts binding
puts binding
puts binding == binding
# =>
#<Binding:0x9769ea0>
#<Binding:0x9769ea0>
#<Binding:0x9941ea8>
#<Binding:0x9941e58>
false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With