Skip to content

Commit 4596986

Browse files
committed
Add code for namespacing Ruby feature.
1 parent 228c2db commit 4596986

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

_posts/2025-06-06-may-rubygems-updates.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,45 @@ Ruby version usage continues to trend steadily toward modern releases. In May 20
5555
| *(unknown)* | 1.21% | 1.10% | 2.42% | Missing user agent info |
5656

5757

58-
## Ruby news
58+
## Interesting Ruby news
5959

6060
**Experimental Namespacing Lands in Ruby Master**
6161

6262
- A new **experimental namespacing** feature [has been introduced in Ruby master](https://bugs.ruby-lang.org/issues/21311), allowing the creation of **virtual top-level namespaces**.
6363
- This enables applications to `require` or `load` libraries in isolation from the global namespace—including `.rb` files and native extensions. Dependencies loaded within a namespace remain confined to it.
6464
- Namespacing helps avoid **name conflicts** between libraries that define the same modules or classes, and prevents **unintended sharing of global objects**.
6565
- The feature opens the door for safer, more modular Ruby applications.
66+
- Join the discussions (for example [the one about feature final name](https://bugs.ruby-lang.org/issues/21385)) and help shaping the future of Ruby!
67+
68+
```ruby
69+
# app1.rb
70+
PORT = 2048
71+
class App
72+
def self.port = ::PORT
73+
end
74+
```
75+
76+
```ruby
77+
# app2.rb
78+
PORT = 4096
79+
class App
80+
def self.port = ::PORT
81+
end
82+
```
83+
84+
```ruby
85+
# main.rb
86+
app1 = Namespace.new
87+
app1.require('/app1.rb')
88+
89+
app2 = Namespace.new
90+
app2.require('/app2.rb')
91+
92+
puts app1::App.port # => 2048
93+
puts app2::App.port # => 4096
94+
95+
puts defined?(PORT) # => nl
96+
```
6697

6798
## Thank you
6899

0 commit comments

Comments
 (0)