ruby-changes:65159
From: aycabta <ko1@a...>
Date: Sat, 6 Feb 2021 21:09:45 +0900 (JST)
Subject: [ruby-changes:65159] 7b354cf67b (master): [ruby/irb] Enable to reassign a new block with "measure" command
https://git.ruby-lang.org/ruby.git/commit/?id=7b354cf67b From 7b354cf67ba95305b600cc8b3ba684923cdc5a98 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Sat, 6 Feb 2021 21:07:11 +0900 Subject: [ruby/irb] Enable to reassign a new block with "measure" command https://github.com/ruby/irb/commit/b444573aa2 --- lib/irb/init.rb | 8 ++++++++ test/irb/test_cmd.rb | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/irb/init.rb b/lib/irb/init.rb index cd57012..78ef2fa 100644 --- a/lib/irb/init.rb +++ b/lib/irb/init.rb @@ -157,6 +157,14 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/init.rb#L157 added = [:CUSTOM, IRB.conf[:MEASURE_PROC][:CUSTOM], arg] elsif block_given? added = [:BLOCK, block, arg] + found = IRB.conf[:MEASURE_CALLBACKS].find{ |m| m[0] == added[0] && m[2] == added[2] } + if found + found[1] = block + return added + else + IRB.conf[:MEASURE_CALLBACKS] << added + return added + end else added = [:TIME, IRB.conf[:MEASURE_PROC][:TIME], arg] end diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb index 045ce0f..7219473 100644 --- a/test/irb/test_cmd.rb +++ b/test/irb/test_cmd.rb @@ -294,6 +294,13 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_cmd.rb#L294 "measure { |context, code, line_no, &block|\n", " result = block.()\n", " puts 'aaa' if IRB.conf[:MEASURE]\n", + " result\n", + "}\n", + "3\n", + "measure { |context, code, line_no, &block|\n", + " result = block.()\n", + " puts 'bbb' if IRB.conf[:MEASURE]\n", + " result\n", "}\n", "3\n", "measure :off\n", @@ -306,7 +313,7 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_cmd.rb#L313 irb.eval_input end assert_empty err - assert_match(/\A=> 3\nBLOCK is added\.\n=> nil\naaa\n=> 3\n=> nil\n=> 3\n/, out) + assert_match(/\A=> 3\nBLOCK is added\.\n=> nil\naaa\n=> 3\nBLOCK is added.\naaa\n=> nil\nbbb\n=> 3\n=> nil\n=> 3\n/, out) assert_empty(c.class_variables) end -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/