[ruby-core:102803] [Ruby master Feature#17674] Proposal: `Method#source_location` or `Method#owner` for refined methods
From:
manga.osyo@...
Date:
2021-03-10 13:31:04 UTC
List:
ruby-core #102803
Issue #17674 has been updated by osyo (manga osyo).
hi.
In Ruby 2.7 and later, `#method` supports Refinements.
```ruby
# test.rb
module Cover
refine Range do
def cover?(value)
return super unless value.is_a?(Range)
super(value.first) && super(value.last)
end
end
end
using Cover
pp (1..10).method(:cover?).source_location
# Ruby 2.6 => nil
# Ruby 2.7 => ["/test.rb", 4]
pp (1..10).method(:cover?).owner
# Ruby 2.6 => Range
# Ruby 2.7 => #<refinement:Range@Cover>
```
see: https://bugs.ruby-lang.org/issues/15373
----------------------------------------
Feature #17674: Proposal: `Method#source_location` or `Method#owner` for refined methods
https://bugs.ruby-lang.org/issues/17674#change-90824
* Author: AlexWayfer (Alexander Popov)
* Status: Open
* Priority: Normal
----------------------------------------
Inspired by https://bugs.ruby-lang.org/issues/15504#note-17
I'm working on a gem with Ruby refinements, and some methods are invented in new Ruby versions like 2.5 or 3.0, and I'd like to define in this gem should I refine a method or not.
So… current behavior of `Method#source_location` returns `nil` for core and/or refined methods. I think, refinements should be caught by this method. Also I didn't know about `Method#owner`, but it can be a case for refinements too.
--
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>