ボクシング・デーのRuby

$ cat box.rb
class String
def greet
"Hello, #{self}!"
end
end

box = Ruby::Box.new
box.eval <<'END'
class String
def greet
"Happy holidays, #{self}!"
end
end
END

puts "World".greet

box.eval <<'END'
puts "World".greet
END
$ RUBY_BOX=1 ruby box.rb
ruby: warning: Ruby::Box is experimental, and the behavior may change in the future!
See https://docs.ruby-lang.org/en/4.0/Ruby/Box.html for known issues, etc.
Hello, World!
Happy holidays, World!

もっとおもしろいことできそうよね

Ruby::Box ダイジェスト紹介(Ruby 4.0.0 新機能) - STORES Product Blog
https://product.st.inc/entry/2025/12/25/134453

0

If you have a fediverse account, you can quote this note from your own instance. Search https://mastodon.zunda.ninja/users/zundan/statuses/115782171405524344 on your instance and quote it. (Note that quoting is not supported in Mastodon.)