diff options
author | tomoya ishida <tomoyapenguin@gmail.com> | 2023-12-13 20:06:21 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-12-13 11:06:26 +0000 |
commit | 745ab3e4c748ebf3b22278d7ad33c7abcf1f6016 (patch) | |
tree | d9b25cf5cfadd7b3f059e84d1bfbc361c5ad4717 /lib/irb/cmd | |
parent | a7ad9f38367b729d49db78e7cbe13922d3ff70ee (diff) |
[ruby/irb] Warn and do nothing if block is passed to measure command
(https://github.com/ruby/irb/pull/813)
https://github.com/ruby/irb/commit/e79a90a1e6
Diffstat (limited to 'lib/irb/cmd')
-rw-r--r-- | lib/irb/cmd/measure.rb | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/lib/irb/cmd/measure.rb b/lib/irb/cmd/measure.rb index 9122e2dac9..4e1125a0a6 100644 --- a/lib/irb/cmd/measure.rb +++ b/lib/irb/cmd/measure.rb @@ -12,32 +12,29 @@ module IRB super(*args) end - def execute(type = nil, arg = nil, &block) + def execute(type = nil, arg = nil) # Please check IRB.init_config in lib/irb/init.rb that sets # IRB.conf[:MEASURE_PROC] to register default "measure" methods, # "measure :time" (abbreviated as "measure") and "measure :stackprof". + + if block_given? + warn 'Configure IRB.conf[:MEASURE_PROC] to add custom measure methods.' + return + end + case type when :off - IRB.conf[:MEASURE] = nil IRB.unset_measure_callback(arg) when :list IRB.conf[:MEASURE_CALLBACKS].each do |type_name, _, arg_val| puts "- #{type_name}" + (arg_val ? "(#{arg_val.inspect})" : '') end when :on - IRB.conf[:MEASURE] = true - added = IRB.set_measure_callback(type, arg) + added = IRB.set_measure_callback(arg) puts "#{added[0]} is added." if added else - if block_given? - IRB.conf[:MEASURE] = true - added = IRB.set_measure_callback(&block) - puts "#{added[0]} is added." if added - else - IRB.conf[:MEASURE] = true - added = IRB.set_measure_callback(type, arg) - puts "#{added[0]} is added." if added - end + added = IRB.set_measure_callback(type, arg) + puts "#{added[0]} is added." if added end nil end |