123456789_123456789_123456789_123456789_123456789_

Class: IRB::Command::Measure

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Base
Instance Chain:
Inherits: IRB::Command::Base
Defined in: lib/irb/command/measure.rb

Class Method Summary

Instance Attribute Summary

Base - Inherited

Instance Method Summary

Constructor Details

.new(*args) ⇒ Measure

[ GitHub ]

  
# File 'lib/irb/command/measure.rb', line 11

def initialize(*args)
  super(*args)
end

Instance Method Details

#execute(arg)

[ GitHub ]

  
# 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)

[ GitHub ]

  
# 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