Class: IRB::ExtendCommand::Measure

Inherits:
Nop show all
Defined in:
lib/irb/cmd/measure.rb

Instance Attribute Summary

Attributes inherited from Nop

#irb_context

Instance Method Summary collapse

Methods inherited from Nop

execute, #irb

Constructor Details

#initialize(*args) ⇒ Measure

Returns a new instance of Measure.



7
8
9
# File 'lib/irb/cmd/measure.rb', line 7

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

Instance Method Details

#execute(type = nil, arg = nil, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/irb/cmd/measure.rb', line 11

def execute(type = nil, arg = nil, &block)
  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