
Issue #21365 has been updated by Eregon (Benoit Daloze). `ns.eval "self"` would be the Namespace "main" object, not the `Namespace` instance itself, so `instance_eval` would be a bad fit here. AFAIK, `instance_eval` is only called as such because any `def foo; end` inside it will definite a singleton method on the instance. And similarly `class_eval` defines `def foo; end` as a class instance method. This is not relevant here, `def foo; end` would have normal top-level `def` semantics (in that namespace). ---------------------------------------- Feature #21365: Add `Namespace#eval` https://bugs.ruby-lang.org/issues/21365#change-113438 * Author: tenderlovemaking (Aaron Patterson) * Status: Open ---------------------------------------- I would like a way to eval code on to a `Namespace` object. Could we add an eval method that _doesn't_ take a binding object? Writing a new file every time I want to test Namespaces is too cumbersome. Thanks! -- https://bugs.ruby-lang.org/