Feature #20712
closed
module should return newly defined module
Added by esad (Esad Hajdarevic) 2 months ago.
Updated 2 months ago.
Description
Currently module keyword returns nil after defining a new module:
x = module Foo
end
# x is nil
It would be more consistent with Module.new
if module keyword returned the newly defined module. Then we could do:
using(module Foo
refine ...
end)
instead of
module Foo
end
using Foo
- Description updated (diff)
Ok I was too quick on this one. module keyword returns last expression in the block, so just ending module declaration with self works:
using(module Foo
refine ...
self
end)
so this request can be closed
module
and class
don't return nil
, they return the value of the last statement in the scope:
x = module Foo
42
end
puts x #=> 42
x = class Bar
def foo = 42
end
puts x #=> :foo
There might be code that relies on this fact, so the proposal could be a backward compatibility concern.
On the other hand, if this were to change, since method definitions (i.e. def
s) return the name of the method defined and not the method object itself, I think it would make more sense for module
/class
to return the name of the module/class being defined and not the module/class object itself.
- Status changed from Open to Closed
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0