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

ruby-changes:64565

From: aycabta <ko1@a...>
Date: Thu, 24 Dec 2020 23:32:36 +0900 (JST)
Subject: [ruby-changes:64565] 167dc37632 (master): [ruby/irb] Try not to register the exact same measuring method twice

https://git.ruby-lang.org/ruby.git/commit/?id=167dc37632

From 167dc37632300e0061351ab87ddc89ebe9c5f53f Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Thu, 24 Dec 2020 22:09:09 +0900
Subject: [ruby/irb] Try not to register the exact same measuring method twice

https://github.com/ruby/irb/commit/cc66b5573e

diff --git a/lib/irb/cmd/measure.rb b/lib/irb/cmd/measure.rb
index 0806f84..5e0bef6 100644
--- a/lib/irb/cmd/measure.rb
+++ b/lib/irb/cmd/measure.rb
@@ -20,11 +20,11 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/cmd/measure.rb#L20
         when :on
           IRB.conf[:MEASURE] = true
           added = IRB.set_measure_callback(type, arg)
-          puts "#{added[0]} is added."
+          puts "#{added[0]} is added." if added
         else
           IRB.conf[:MEASURE] = true
           added = IRB.set_measure_callback(type, arg)
-          puts "#{added[0]} is added."
+          puts "#{added[0]} is added." if added
         end
         nil
       end
diff --git a/lib/irb/init.rb b/lib/irb/init.rb
index 45a35cf..8428a42 100644
--- a/lib/irb/init.rb
+++ b/lib/irb/init.rb
@@ -158,8 +158,18 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/init.rb#L158
     else
       added = [:TIME, IRB.conf[:MEASURE_PROC][:TIME], arg]
     end
-    IRB.conf[:MEASURE_CALLBACKS] << added if added
-    added
+    if added
+      found = IRB.conf[:MEASURE_CALLBACKS].find{ |m| m[0] == added[0] && m[2] == added[2] }
+      if found
+        # already added
+        nil
+      else
+        IRB.conf[:MEASURE_CALLBACKS] << added if added
+        added
+      end
+    else
+      nil
+    end
   end
 
   def IRB.unset_measure_callback(type = nil)
-- 
cgit v0.10.2


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

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