зеркало из https://github.com/github/ruby.git
[ruby/irb] Enable to reassign a new block with "measure" command
https://github.com/ruby/irb/commit/b444573aa2
This commit is contained in:
Родитель
5704b5fe5e
Коммит
7b354cf67b
|
@ -157,6 +157,14 @@ module IRB # :nodoc:
|
|||
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
|
||||
|
|
|
@ -294,6 +294,13 @@ module TestIRB
|
|||
"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
|
|||
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
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче