[前][次][番号順一覧][スレッド一覧]

ruby-changes:63453

From: Nobuyoshi <ko1@a...>
Date: Tue, 27 Oct 2020 16:13:32 +0900 (JST)
Subject: [ruby-changes:63453] 3198e7abd7 (master): Separate `send` into `public_send` and `__send__`

https://git.ruby-lang.org/ruby.git/commit/?id=3198e7abd7

From 3198e7abd70bd2af977f2bb6c967e9df8f91adb0 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 27 Oct 2020 13:42:52 +0900
Subject: Separate `send` into `public_send` and `__send__`


diff --git a/lib/csv/row.rb b/lib/csv/row.rb
index a2d03e8..fd293a0 100644
--- a/lib/csv/row.rb
+++ b/lib/csv/row.rb
@@ -84,7 +84,7 @@ class CSV https://github.com/ruby/ruby/blob/trunk/lib/csv/row.rb#L84
     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?
diff --git a/lib/drb/observer.rb b/lib/drb/observer.rb
index 3ee1533..0fb7301 100644
--- a/lib/drb/observer.rb
+++ b/lib/drb/observer.rb
@@ -13,7 +13,7 @@ module DRb https://github.com/ruby/ruby/blob/trunk/lib/drb/observer.rb#L13
         if defined? @observer_peers
           @observer_peers.each do |observer, method|
             begin
-              observer.send(method, *arg)
+              observer.__send__(method, *arg)
             rescue
               delete_observer(observer)
             end
diff --git a/lib/forwardable.rb b/lib/forwardable.rb
index d0f49f7..c720feb 100644
--- a/lib/forwardable.rb
+++ b/lib/forwardable.rb
@@ -189,7 +189,7 @@ module Forwardable https://github.com/ruby/ruby/blob/trunk/lib/forwardable.rb#L189
     # 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 https://github.com/ruby/ruby/blob/trunk/lib/forwardable.rb#L309
     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
 
diff --git a/lib/irb/cmd/fork.rb b/lib/irb/cmd/fork.rb
index 19c78fc..7566d10 100644
--- a/lib/irb/cmd/fork.rb
+++ b/lib/irb/cmd/fork.rb
@@ -16,7 +16,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/cmd/fork.rb#L16
   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')
diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb
index c9328e5..6d82139 100644
--- a/lib/irb/completion.rb
+++ b/lib/irb/completion.rb
@@ -268,7 +268,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L268
     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)
diff --git a/lib/irb/easter-egg.rb b/lib/irb/easter-egg.rb
index 64869d8..3e79692 100644
--- a/lib/irb/easter-egg.rb
+++ b/lib/irb/easter-egg.rb
@@ -126,6 +126,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/easter-egg.rb#L126
             print "\e[H" + buff
             sleep 0.05
           end
+        rescue Interrupt
         ensure
           print "\e[0m\e[?1049l"
         end
@@ -134,4 +135,4 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/easter-egg.rb#L135
   end
 end
 
-IRB.send(:easter_egg, ARGV[0]&.to_sym) if $0 == __FILE__
+IRB.__send__(:easter_egg, ARGV[0]&.to_sym) if $0 == __FILE__
diff --git a/lib/irb/extend-command.rb b/lib/irb/extend-command.rb
index 2f4fcfb..3cd0c51 100644
--- a/lib/irb/extend-command.rb
+++ b/lib/irb/extend-command.rb
@@ -180,7 +180,7 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/extend-command.rb#L180
                 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: https://github.com/ruby/ruby/blob/trunk/lib/irb/extend-command.rb#L268
         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: https://github.com/ruby/ruby/blob/trunk/lib/irb/extend-command.rb#L291
       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: https://github.com/ruby/ruby/blob/trunk/lib/irb/extend-command.rb#L307
       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
diff --git a/lib/irb/workspace.rb b/lib/irb/workspace.rb
index 794a511..97d3c5f 100644
--- a/lib/irb/workspace.rb
+++ b/lib/irb/workspace.rb
@@ -52,7 +52,7 @@ EOF https://github.com/ruby/ruby/blob/trunk/lib/irb/workspace.rb#L52
           @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)
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index 383579e..672c544 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -784,7 +784,7 @@ int main() {printf("%"PRI_CONFTEST_PREFIX"#{neg ? 'd' : 'u'}\\n", conftest_const https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L784
     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 https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L982
       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?
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb
index aff9e7e..bd8c8ab 100644
--- a/lib/net/ftp.rb
+++ b/lib/net/ftp.rb
@@ -1049,7 +1049,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L1049
         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
diff --git a/lib/net/imap.rb b/lib/net/imap.rb
index de13d08..ae23c0a 100644
--- a/lib/net/imap.rb
+++ b/lib/net/imap.rb
@@ -1542,7 +1542,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L1542
 
     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 https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L1557
 
     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 https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L1572
 
     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 https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L1587
 
     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 https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L1602
 
     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
diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb
index 810da77..e58d8fb 100644
--- a/lib/net/smtp.rb
+++ b/lib/net/smtp.rb
@@ -745,7 +745,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/smtp.rb#L745
     def authenticate(user, secret, authtype = DEFAULT_AUTH_TYPE)
       check_auth_method authtype
       check_auth_args user, secret
-      send auth_method(authtype), user, secret
+     (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]