Sha256: b6051533201748c63daa758a014b6af2a6176c461d39c9c991cbc73ed42a4c0b

Contents?: true

Size: 1.39 KB

Versions: 24

Compression:

Stored size: 1.39 KB

Contents

require_relative "nop"

module IRB
  # :stopdoc:

  module ExtendCommand
    class Measure < Nop
      category "Misc"
      description "`measure` enables the mode to measure processing time. `measure :off` disables it."

      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

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
study_line-0.1.6 vendor/bundle/ruby/3.2.0/gems/irb-1.8.3/lib/irb/cmd/measure.rb
study_line-0.1.5 vendor/bundle/ruby/3.2.0/gems/irb-1.8.3/lib/irb/cmd/measure.rb
study_line-0.1.4 vendor/bundle/ruby/3.2.0/gems/irb-1.8.3/lib/irb/cmd/measure.rb
study_line-0.1.3 vendor/bundle/ruby/3.2.0/gems/irb-1.8.3/lib/irb/cmd/measure.rb
irb-1.10.1 lib/irb/cmd/measure.rb
study_line-0.1.2 vendor/bundle/ruby/3.2.0/gems/irb-1.8.3/lib/irb/cmd/measure.rb
study_line-0.1.1 vendor/bundle/ruby/3.2.0/gems/irb-1.8.3/lib/irb/cmd/measure.rb
irb-1.10.0 lib/irb/cmd/measure.rb
irb-1.9.1 lib/irb/cmd/measure.rb
irb-1.9.0 lib/irb/cmd/measure.rb
irb-1.8.3 lib/irb/cmd/measure.rb
irb-1.8.2 lib/irb/cmd/measure.rb
irb-1.8.1 lib/irb/cmd/measure.rb
irb-1.8.0 lib/irb/cmd/measure.rb
irb-1.7.4 lib/irb/cmd/measure.rb
irb-1.7.3 lib/irb/cmd/measure.rb
irb-1.7.2 lib/irb/cmd/measure.rb
irb-1.7.1 lib/irb/cmd/measure.rb
irb-1.7.0 lib/irb/cmd/measure.rb
irb-1.6.4 lib/irb/cmd/measure.rb