Project

General

Profile

Actions

Feature #15373

closed

Proposal: Enable refinements to `#method` and `#instance_method`

Added by osyo (manga osyo) over 5 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:90253]

Description

Proposal enable refinements to #method and #instance_method.
It can be used in the following cases.

# default call to #pp
module P2PP
  refine Kernel do
    def p obj
      pp obj
    end
  end
end

using P2PP

# call to Kernel.#pp
[1, 2, 3].map(&method(:p))

Also, when checking the defined position as follows, the refine place is reflected.

module P2PP
  refine Kernel do
    def p obj
      pp obj
    end
  end
end

# Output to refine defined position
# Before
p method(:p).source_location
# => nil
p Kernel.instance_method(:p).source_location
# => nil

using P2PP

# After
p method(:p).source_location
# => ["../ruby/test.rb", 4]
p Kernel.instance_method(:p).source_location
# => ["../ruby/test.rb", 4]

I want .: operators to work.
https://bugs.ruby-lang.org/issues/13581

pull reqiest: https://github.com/ruby/ruby/pull/2034

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0