[ruby-core:105843] [Ruby master Feature#11919] Passing a module directly
From:
"Eregon (Benoit Daloze)" <noreply@...>
Date:
2021-10-28 11:02:09 UTC
List:
ruby-core #105843
Issue #11919 has been updated by Eregon (Benoit Daloze).
I'm rather neutral about this.
On one hand, I think `using Module.new {` is clearer that there is a module involved and might avoid some confusion when learning about refinements,
OTOH it seems a fairly harmless shorthand which doesn't do too much magic.
----------------------------------------
Feature #11919: Passing a module directly
https://bugs.ruby-lang.org/issues/11919#change-94377
* Author: sawa (Tsuyoshi Sawada)
* Status: Feedback
* Priority: Normal
----------------------------------------
Refinement requires a named module:
~~~ruby
module MyRefinement
refine ...
...
end
using MyRefinement
~~~
but often (but not always), refinements are called by the `using` command only in once in a single file, and should not need to be named in such case. Also, the purpose of refinement is to not pollute classes with methods. Necessity to define a module and polluting the name space looks to me to go against this idea.
I would like to do:
~~~ruby
using Module.new do
refine ...
...
end
~~~
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>