Project

General

Profile

Actions

Feature #15326

closed

Proposal: Enable refinements to `#public_send`

Added by osyo (manga osyo) about 6 years ago. Updated almost 6 years ago.

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

Description

Sometimes we use #public_send rather than #send to avoid calling the private method.

def meth(a)
  # Not call private method
  # Use #public_send
  a.public_send(a.name)
end

However, #send support to refinements, but #public_send does not support refinements.

class X
  def name
    "hoge"
  end
end

module Ex
  refine X do
    def hoge
      # ...
    end
  end
end

using Ex

def meth(a)
  # Not call private method
  # Use #public_send
  a.public_send(a.name)
end


# Error: undefined method `hoge' for #<X:0x0000561a8cc7e280> (NoMethodError)
meth X.new

#public_send also wants to support refinements.

pull request : https://github.com/ruby/ruby/pull/2019

Actions

Also available in: Atom PDF

Like0
Like0