Project

General

Profile

Feature #11919

Passing a module directly

Added by sawa (Tsuyoshi Sawada) over 3 years ago. Updated over 3 years ago.

Status:
Feedback
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:72584]

Description

Refinement requires a named module:

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:

using Module.new do
  refine ...
  ...
end

History

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

  • Description updated (diff)
  • Status changed from Open to Feedback

You can write it as

using Module.new {
  refine ...
  ...
}

Or without Module.new?

using do
  refine ...
  ...
end

Updated by sawa (Tsuyoshi Sawada) over 3 years ago

Nobuyoshi Nakada wrote:

You can write it as

using Module.new {
  refine ...
  ...
}

Right. I had forgotten about operator precedence. My example did not make sense.

Or without Module.new?

using do
  refine ...
  ...
end

I think this is what I actually wanted to ask for.

Also available in: Atom PDF