Project

General

Profile

Feature #7418

Kernel#used_refinements

Added by Charlie Somerville about 4 years ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
[ruby-core:49805]

Description

I'd like to propose a method that returns an array of all refinements visible from the current scope. I have documented the ordering of the return array as undefined to allow a bit of flexibility in how it is implemented across the various Ruby implementations.

One of the criticisms of refinements is that its use makes code harder to understand - especially when non-lexical refinements are being used. This method slightly improves the situation by making debugging of code using refinements easier.

I've named the method 'used_refinements' for now, but I'm open to changing that to something else.

I've already done the initial implementation which is attached as a patch. Feedback would be most appreciated.

used_refinements.patch View (3.06 KB) Charlie Somerville, 11/21/2012 08:16 PM

Associated revisions

Revision 56094
Added by Shugo Maeda 3 months ago

  • eval.c (rb_mod_s_used_refinements): new method Module.used_refinements. based on the patch by Charlie Somerville. [Feature #7418]

Revision 56109
Added by Shugo Maeda 3 months ago

  • eval.c (rb_mod_s_used_modules): rename Module.used_refinements to Module.used_modules. [Feature #7418]

History

#1 [ruby-core:49812] Updated by Magnus Holm about 4 years ago

Maybe it should be called Module.refinements (a la Module.nesting).

// Magnus Holm

On Wed, Nov 21, 2012 at 12:16 PM, charliesome (Charlie Somerville)
charlie@charliesomerville.com wrote:

Issue #7418 has been reported by charliesome (Charlie Somerville).


Feature #7418: Kernel#used_refinements
https://bugs.ruby-lang.org/issues/7418

Author: charliesome (Charlie Somerville)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:

I'd like to propose a method that returns an array of all refinements visible from the current scope. I have documented the ordering of the return array as undefined to allow a bit of flexibility in how it is implemented across the various Ruby implementations.

One of the criticisms of refinements is that its use makes code harder to understand - especially when non-lexical refinements are being used. This method slightly improves the situation by making debugging of code using refinements easier.

I've named the method 'used_refinements' for now, but I'm open to changing that to something else.

I've already done the initial implementation which is attached as a patch. Feedback would be most appreciated.

--
http://bugs.ruby-lang.org/

#2 [ruby-core:49850] Updated by Shugo Maeda about 4 years ago

  • Assignee set to Shugo Maeda
  • Status changed from Open to Assigned

judofyr (Magnus Holm) wrote:

Maybe it should be called Module.refinements (a la Module.nesting).

Module.refinements conflicts with Module#refinements, which returns refinements defined in the receiver.

#3 Updated by Jack Chen about 4 years ago

+1 since I gave Charlie the idea :)

#4 [ruby-core:49984] Updated by Yusuke Endoh about 4 years ago

  • Target version set to next minor

Shugo, is this feature mandatory for the 2.0.0 refinements?
I'm setting to next minor tentatively.

--
Yusuke Endoh mame@tsg.ne.jp

#5 [ruby-core:55759] Updated by Shugo Maeda over 3 years ago

  • Assignee changed from Shugo Maeda to Yukihiro Matsumoto

I'm against adding a new reflection API for refinements into Ruby 2.1.
What do you think of it, Matz?

#6 [ruby-core:77183] Updated by Yukihiro Matsumoto 3 months ago

Module.used_refinements accepted.

Matz.

#7 Updated by Shugo Maeda 3 months ago

  • Status changed from Assigned to Closed

Applied in changeset r56094.


  • eval.c (rb_mod_s_used_refinements): new method Module.used_refinements. based on the patch by Charlie Somerville. [Feature #7418]

#8 [ruby-core:77214] Updated by Shugo Maeda 3 months ago

  • Status changed from Closed to Open

Module.used_refinements accepted.

Module.used_modules might be a better name, because a module can have more than one refinement:

module M
  refine A
  end

  refine B
  end
end

using M
p Module.used_modules #=> [M]

#9 [ruby-core:77217] Updated by Shugo Maeda 3 months ago

Shugo Maeda wrote:

Module.used_modules might be a better name, because a module can have more than one refinement:

Matz said that he thinks so too at https://twitter.com/yukihiro_matz/status/773787246990196736, so I'll change the name.

#10 Updated by Shugo Maeda 3 months ago

  • Status changed from Open to Closed

Applied in changeset r56109.


  • eval.c (rb_mod_s_used_modules): rename Module.used_refinements to Module.used_modules. [Feature #7418]

Also available in: Atom PDF