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