Actions
Feature #15327
closedProposal: Enable refinements to `#respond_to?`
Status:
Closed
Assignee:
-
Target version:
-
Description
Refinements are enabled with various contexts and methods.
#send
#__send__
- Symbol#to_proc
-
#to_s
- called by
"#{hoge}"
- called by
-
#to_proc
- call to
&:hoge
- since ruby 2.6
- call to
I want to enable refinements for #respond_to?
I want to use it in the following case.
module StringEx
refine String do
def twice
self + self
end
end
end
class X
using StringEx
def meth a
a.twice if a.respond_to? :twice
end
end
class Y
def twice
42 + 42
end
end
x = X.new
p x.meth Y.new
# => 84
p x.meth "homu"
# => "homuhomu"
p x.meth 42
# nil
pull request : https://github.com/ruby/ruby/pull/2020
Actions
Like0
Like0Like0