3 ms·
To make sure code loaded from gems doesn’t shadow the namespace of the application.
by Manfred 1y ago
To make sure code loaded from gems doesn’t shadow the namespace of the application.
- dudeinjapan 1y agoRight. Today Ruby has essentially a global namespace, where every defined module/class/const is put in the same "global dumping ground" and can override/"monkey patch" each other. Ruby 3.5 will introduce a new language keyword "namespace" that scopes behavior to that namespace. class Foo def foo; puts "foo"; end end namespace Bar class Foo def foo; puts "bar"; end end Foo.new.foo #=> "bar" end Foo.new.foo #=> "foo" Fun times. This is intended for isolated code loading similar to "modules" in Python or ES6, but I am worried it will be abused badly. I'm also unsure whether they will add a "use Namespace" construct... See here: https://bugs.ruby-lang.org/issues/21311 https://bugs.ruby-lang.org/issues/21311