1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/irb/cmd/measure.rb
Nobuyoshi Nakada 8760b270ed [ruby/irb] Move :stopdoc: directive
If this is at the top level, it stops the documentation of the
entire module, but not only the part in this file.

https://github.com/ruby/irb/commit/86c41b06ad
2022-03-14 14:40:28 +09:00

45 lines
1.3 KiB
Ruby

require_relative "nop"
module IRB
# :stopdoc:
module ExtendCommand
class Measure < Nop
def initialize(*args)
super(*args)
end
def execute(type = nil, arg = nil, &block)
# 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".
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)
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
end
nil
end
end
end
# :startdoc:
end