2020-08-14 17:36:24 -04:00
|
|
|
require_relative "nop"
|
|
|
|
|
|
|
|
# :stopdoc:
|
|
|
|
module IRB
|
|
|
|
module ExtendCommand
|
|
|
|
class Measure < Nop
|
|
|
|
def initialize(*args)
|
|
|
|
super(*args)
|
|
|
|
end
|
|
|
|
|
2021-02-06 06:23:51 -05:00
|
|
|
def execute(type = nil, arg = nil, &block)
|
2021-07-13 08:21:35 -04:00
|
|
|
# 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".
|
2020-08-14 17:36:24 -04:00
|
|
|
case type
|
|
|
|
when :off
|
|
|
|
IRB.conf[:MEASURE] = nil
|
|
|
|
IRB.unset_measure_callback(arg)
|
|
|
|
when :list
|
2020-12-21 15:08:12 -05:00
|
|
|
IRB.conf[:MEASURE_CALLBACKS].each do |type_name, _, arg_val|
|
|
|
|
puts "- #{type_name}" + (arg_val ? "(#{arg_val.inspect})" : '')
|
2020-08-14 17:36:24 -04:00
|
|
|
end
|
|
|
|
when :on
|
|
|
|
IRB.conf[:MEASURE] = true
|
2020-12-21 14:56:03 -05:00
|
|
|
added = IRB.set_measure_callback(type, arg)
|
2020-12-24 08:09:09 -05:00
|
|
|
puts "#{added[0]} is added." if added
|
2020-08-14 17:36:24 -04:00
|
|
|
else
|
2021-02-06 06:23:51 -05:00
|
|
|
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
|
2020-08-14 17:36:24 -04:00
|
|
|
end
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# :startdoc:
|