From 2f00046758a06a539d1b9410fcabfd56cf854d51 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 10 Jun 2025 11:28:18 +0900 Subject: [PATCH] mruby-toplevel-ext: add README.md The document is written by Google Jules. --- mrbgems/mruby-toplevel-ext/README.md | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 mrbgems/mruby-toplevel-ext/README.md diff --git a/mrbgems/mruby-toplevel-ext/README.md b/mrbgems/mruby-toplevel-ext/README.md new file mode 100644 index 000000000..181bc2867 --- /dev/null +++ b/mrbgems/mruby-toplevel-ext/README.md @@ -0,0 +1,32 @@ +# mruby-toplevel-ext + +mruby-toplevel-ext is a gem that modifies the toplevel in mruby by making the `include` method private. This means modules must be included directly into `Object` (e.g., `Object.include MyModule`) rather than at the toplevel. + +## Usage + +After installing this gem, the `include` method at the toplevel (main) becomes private. This is the primary change provided by this gem. + +Consider the following example: + +```ruby +module MyModule + def my_method + puts "Hello from MyModule!" + end +end + +# This will result in a NoMethodError because include is private: +# include MyModule +# my_method + +# Instead, you must include the module directly into Object: +Object.include MyModule +my_method +# => Hello from MyModule! +``` + +This encourages a more explicit way of extending the global object space. + +## License + +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).