Project

General

Profile

Feature #15326

Proposal: Enable refinements to `#public_send`

Added by osyo (manga osyo) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
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

#1

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Status changed from Open to Closed

Applied in changeset trunk|r65919.


Enable refinements to public_send.

[Feature #15326] [Fix GH-2019]

From: manga_osyo manga.osyo@gmail.com

Also available in: Atom PDF