Class: IRB::Command::Measure
- Includes:
- RubyArgsExtractor
- Defined in:
- lib/irb/command/measure.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #execute(arg) ⇒ Object
- #execute_internal(type = nil, arg = nil) ⇒ Object
-
#initialize(*args) ⇒ Measure
constructor
A new instance of Measure.
Methods included from RubyArgsExtractor
#ruby_args, #unwrap_string_literal
Methods inherited from Base
category, description, execute, help_message
Constructor Details
#initialize(*args) ⇒ Measure
Returns a new instance of Measure.
11 12 13 |
# File 'lib/irb/command/measure.rb', line 11 def initialize(*args) super(*args) end |
Instance Method Details
#execute(arg) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/irb/command/measure.rb', line 15 def execute(arg) if arg&.match?(/^do$|^do[^\w]|^\{/) warn 'Configure IRB.conf[:MEASURE_PROC] to add custom measure methods.' return end args, kwargs = ruby_args(arg) execute_internal(*args, **kwargs) end |
#execute_internal(type = nil, arg = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/irb/command/measure.rb', line 24 def execute_internal(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". case type when :off 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 added = IRB.set_measure_callback(arg) puts "#{added[0]} is added." if added else added = IRB.set_measure_callback(type, arg) puts "#{added[0]} is added." if added end nil end |