class method
Module.new
() -> ::Module
() { (::Module arg0) -> untyped } -> ::Module
Module.new → mod
Module.new {|mod| block } → mod
object.c
View on GitHub ↗
static VALUE
rb_mod_initialize(VALUE module)
{
return rb_mod_initialize_exec(module);
}
Creates a new anonymous module. If a block is given, it is passed the module object, and the block is evaluated in the context of this module like module_eval.
Example
fred = Module.new do def meth1 "hello" end def meth2 "bye" end end a = "my string" a.extend(fred) #=> "my string" a.meth1 #=> "hello" a.meth2 #=> "bye"
Assign the module to a constant (name starting uppercase) if you want to treat it like a regular module.
See also
.nesting
.used_modules
.constants
.used_refinements
also in
4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0