Separate `send` into `public_send` and `__send__`

This commit is contained in:
Nobuyoshi Nakada 2020-10-27 13:42:52 +09:00
Родитель acdb893338
Коммит 3198e7abd7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7CD2805BFA3770C6
22 изменённых файлов: 43 добавлений и 42 удалений

Просмотреть файл

@ -84,7 +84,7 @@ class CSV
def field(header_or_index, minimum_index = 0)
# locate the pair
finder = (header_or_index.is_a?(Integer) || header_or_index.is_a?(Range)) ? :[] : :assoc
pair = @row[minimum_index..-1].send(finder, header_or_index)
pair = @row[minimum_index..-1].public_send(finder, header_or_index)
# return the field if we have a pair
if pair.nil?

Просмотреть файл

@ -13,7 +13,7 @@ module DRb
if defined? @observer_peers
@observer_peers.each do |observer, method|
begin
observer.send(method, *arg)
observer.__send__(method, *arg)
rescue
delete_observer(observer)
end

Просмотреть файл

@ -189,7 +189,7 @@ module Forwardable
# If it's not a class or module, it's an instance
mod = Module === self ? self : singleton_class
ret = mod.module_eval(&gen)
mod.send(:ruby2_keywords, ali) if RUBY_VERSION >= '2.7'
mod.__send__(:ruby2_keywords, ali) if RUBY_VERSION >= '2.7'
ret
end
@ -309,7 +309,7 @@ module SingleForwardable
gen = Forwardable._delegator_method(self, accessor, method, ali)
ret = instance_eval(&gen)
singleton_class.send(:ruby2_keywords, ali) if RUBY_VERSION >= '2.7'
singleton_class.__send__(:ruby2_keywords, ali) if RUBY_VERSION >= '2.7'
ret
end

Просмотреть файл

@ -16,7 +16,7 @@ module IRB
module ExtendCommand
class Fork < Nop
def execute
pid = send ExtendCommand.irb_original_method_name("fork")
pid = __send__ ExtendCommand.irb_original_method_name("fork")
unless pid
class << self
alias_method :exit, ExtendCommand.irb_original_method_name('exit')

Просмотреть файл

@ -268,7 +268,7 @@ module IRB
PerfectMatchedProc = ->(matched, bind: IRB.conf[:MAIN_CONTEXT].workspace.binding) {
RDocRIDriver ||= RDoc::RI::Driver.new
if matched =~ /\A(?:::)?RubyVM/ and not ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
IRB.send(:easter_egg)
IRB.__send__(:easter_egg)
return
end
namespace = retrieve_completion_data(matched, bind: bind, doc_namespace: true)

Просмотреть файл

@ -126,6 +126,7 @@ module IRB
print "\e[H" + buff
sleep 0.05
end
rescue Interrupt
ensure
print "\e[0m\e[?1049l"
end
@ -134,4 +135,4 @@ module IRB
end
end
IRB.send(:easter_egg, ARGV[0]&.to_sym) if $0 == __FILE__
IRB.__send__(:easter_egg, ARGV[0]&.to_sym) if $0 == __FILE__

Просмотреть файл

@ -180,7 +180,7 @@ module IRB # :nodoc:
end
end
], nil, __FILE__, line
send :#{cmd_name}_, *opts, &b
__send__ :#{cmd_name}_, *opts, &b
end
], nil, __FILE__, line
else
@ -268,7 +268,7 @@ module IRB # :nodoc:
def #{cmd_name}(*opts, &b)
Context.module_eval {remove_method(:#{cmd_name})}
require "#{load_file}"
send :#{cmd_name}, *opts, &b
__send__ :#{cmd_name}, *opts, &b
end
for ali in aliases
alias_method ali, cmd_name
@ -291,8 +291,8 @@ module IRB # :nodoc:
module_eval %[
alias_method alias_name, base_method
def #{base_method}(*opts)
send :#{extend_method}, *opts
send :#{alias_name}, *opts
__send__ :#{extend_method}, *opts
__send__ :#{alias_name}, *opts
end
]
end
@ -307,8 +307,8 @@ module IRB # :nodoc:
module_eval %[
alias_method alias_name, base_method
def #{base_method}(*opts)
send :#{alias_name}, *opts
send :#{extend_method}, *opts
__send__ :#{alias_name}, *opts
__send__ :#{extend_method}, *opts
end
]
end

Просмотреть файл

@ -52,7 +52,7 @@ EOF
@binding = BINDING_QUEUE.pop
when 3 # binding in function on TOPLEVEL_BINDING(default)
@binding = eval("self.class.send(:remove_method, :irb_binding) if defined?(irb_binding); private; def irb_binding; binding; end; irb_binding",
@binding = eval("self.class.remove_method(:irb_binding) if defined?(irb_binding); private; def irb_binding; binding; end; irb_binding",
TOPLEVEL_BINDING,
__FILE__,
__LINE__ - 3)

Просмотреть файл

@ -784,7 +784,7 @@ int main() {printf("%"PRI_CONFTEST_PREFIX"#{neg ? 'd' : 'u'}\\n", conftest_const
if opt and !opt.empty?
[[:to_str], [:join, " "], [:to_s]].each do |meth, *args|
if opt.respond_to?(meth)
break opt = opt.send(meth, *args)
break opt = opt.__send__(meth, *args)
end
end
opt = "#{opt} #{libs}"
@ -982,7 +982,7 @@ SRC
if noun
[[:to_str], [:join, ","], [:to_s]].each do |meth, *args|
if noun.respond_to?(meth)
break noun = noun.send(meth, *args)
break noun = noun.__send__(meth, *args)
end
end
unless noun.empty?

Просмотреть файл

@ -1049,7 +1049,7 @@ module Net
raise FTPProtoError, "invalid time-val: #{value}"
end
usec = fractions.to_i * 10 ** (6 - fractions.to_s.size)
Time.send(local ? :local : :utc, year, month, day, hour, min, sec, usec)
Time.public_send(local ? :local : :utc, year, month, day, hour, min, sec, usec)
}
FACT_PARSERS = Hash.new(CASE_DEPENDENT_PARSER)
FACT_PARSERS["size"] = DECIMAL_PARSER

Просмотреть файл

@ -1542,7 +1542,7 @@ module Net
class RawData # :nodoc:
def send_data(imap, tag)
imap.send(:put_string, @data)
imap.__send__(:put_string, @data)
end
def validate
@ -1557,7 +1557,7 @@ module Net
class Atom # :nodoc:
def send_data(imap, tag)
imap.send(:put_string, @data)
imap.__send__(:put_string, @data)
end
def validate
@ -1572,7 +1572,7 @@ module Net
class QuotedString # :nodoc:
def send_data(imap, tag)
imap.send(:send_quoted_string, @data)
imap.__send__(:send_quoted_string, @data)
end
def validate
@ -1587,7 +1587,7 @@ module Net
class Literal # :nodoc:
def send_data(imap, tag)
imap.send(:send_literal, @data, tag)
imap.__send__(:send_literal, @data, tag)
end
def validate
@ -1602,7 +1602,7 @@ module Net
class MessageSet # :nodoc:
def send_data(imap, tag)
imap.send(:put_string, format_internal(@data))
imap.__send__(:put_string, format_internal(@data))
end
def validate

Просмотреть файл

@ -745,7 +745,7 @@ module Net
def authenticate(user, secret, authtype = DEFAULT_AUTH_TYPE)
check_auth_method authtype
check_auth_args user, secret
send auth_method(authtype), user, secret
public_send auth_method(authtype), user, secret
end
def auth_plain(user, secret)

Просмотреть файл

@ -219,7 +219,7 @@ module Observable
if defined? @observer_state and @observer_state
if defined? @observer_peers
@observer_peers.each do |k, v|
k.send v, *arg
k.__send__(v, *arg)
end
end
@observer_state = false

Просмотреть файл

@ -1749,7 +1749,7 @@ XXX
#
def visit(id, *args, &block)
@stack.reverse_each do |el|
el.send(id, *args, &block)
el.__send__(id, *args, &block)
end
nil
end

Просмотреть файл

@ -36,15 +36,15 @@
# Hash keys with spaces or characters that could normally not be used for
# method calls (e.g. <code>()[]*</code>) will not be immediately available
# on the OpenStruct object as a method for retrieval or assignment, but can
# still be reached through the Object#send method or using [].
# still be reached through the Object#__send__ method or using [].
#
# measurements = OpenStruct.new("length (in inches)" => 24)
# measurements[:"length (in inches)"] # => 24
# measurements.send("length (in inches)") # => 24
# measurements.__send__("length (in inches)") # => 24
#
# message = OpenStruct.new(:queued? => true)
# message.queued? # => true
# message.send("queued?=", false)
# message.__send__("queued?=", false)
# message.queued? # => false
#
# Removing the presence of an attribute requires the execution of the

Просмотреть файл

@ -288,7 +288,7 @@ module Racc
end
def add_user_code(label, src)
@result.params.send(USER_CODE_LABELS[label]).push src
@result.params.public_send(USER_CODE_LABELS[label]).push src
end
end

Просмотреть файл

@ -156,7 +156,7 @@ class RDoc::Markup::Formatter
method_name = "handle_regexp_#{name}"
if respond_to? method_name then
target.text = send method_name, target
target.text = public_send method_name, target
handled = true
end
end

Просмотреть файл

@ -1228,7 +1228,7 @@ or the PAGER environment variable.
# +cache+ indicate if it is a class or instance method.
def load_method store, cache, klass, type, name
methods = store.send(cache)[klass]
methods = store.public_send(cache)[klass]
return unless methods

Просмотреть файл

@ -88,7 +88,7 @@ def cp
options[:preserve] = true if options.delete :p
dest = argv.pop
argv = argv[0] if argv.size == 1
FileUtils.send cmd, argv, dest, **options
FileUtils.__send__ cmd, argv, dest, **options
end
end
@ -109,7 +109,7 @@ def ln
options[:force] = true if options.delete :f
dest = argv.pop
argv = argv[0] if argv.size == 1
FileUtils.send cmd, argv, dest, **options
FileUtils.__send__ cmd, argv, dest, **options
end
end
@ -144,7 +144,7 @@ def rm
cmd = "rm"
cmd += "_r" if options.delete :r
options[:force] = true if options.delete :f
FileUtils.send cmd, argv, **options
FileUtils.__send__ cmd, argv, **options
end
end
@ -161,7 +161,7 @@ def mkdir
setup("p") do |argv, options|
cmd = "mkdir"
cmd += "_p" if options.delete :p
FileUtils.send cmd, argv, **options
FileUtils.__send__ cmd, argv, **options
end
end

Просмотреть файл

@ -1097,7 +1097,7 @@ module URI
# # => "http://my.example.com/main.rbx?page=1"
#
def merge(oth)
rel = parser.send(:convert_to_uri, oth)
rel = parser.__send__(:convert_to_uri, oth)
if rel.absolute?
#raise BadURIError, "both URI are absolute" if absolute?
@ -1182,7 +1182,7 @@ module URI
# :stopdoc:
def route_from0(oth)
oth = parser.send(:convert_to_uri, oth)
oth = parser.__send__(:convert_to_uri, oth)
if self.relative?
raise BadURIError,
"relative URI: #{self}"
@ -1290,7 +1290,7 @@ module URI
# #=> #<URI::Generic /main.rbx?page=1>
#
def route_to(oth)
parser.send(:convert_to_uri, oth).route_from(self)
parser.__send__(:convert_to_uri, oth).route_from(self)
end
#
@ -1404,7 +1404,7 @@ module URI
# Returns an Array of the components defined from the COMPONENT Array.
def component_ary
component.collect do |x|
self.send(x)
self.__send__(x)
end
end
protected :component_ary
@ -1429,7 +1429,7 @@ module URI
def select(*components)
components.collect do |c|
if component.include?(c)
self.send(c)
self.__send__(c)
else
raise ArgumentError,
"expected of components of #{self.class} (#{self.class.component.join(', ')})"

Просмотреть файл

@ -85,7 +85,7 @@ module WEBrick
def log(meth, fmt, *args)
msg = format("%s %s: ", @auth_scheme, @realm)
msg << fmt % args
@logger.send(meth, msg)
@logger.__send__(meth, msg)
end
def error(fmt, *args)

Просмотреть файл

@ -115,7 +115,7 @@ module WEBrick
proxy_auth(req, res)
begin
self.send("do_#{req.request_method}", req, res)
public_send("do_#{req.request_method}", req, res)
rescue NoMethodError
raise HTTPStatus::MethodNotAllowed,
"unsupported method `#{req.request_method}'."