Class: Benchmark::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/benchmark.rb

Overview

A Job is a sequence of labelled blocks to be processed by the Benchmark.bmbm method. It is of little direct interest to the user.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width) ⇒ Job

Returns an initialized Job instance. Usually, one doesn’t call this method directly, as new Job objects are created by the #bmbm method. width is a initial value for the label offset used in formatting; the #bmbm method passes its width argument to this constructor.



342
343
344
345
# File 'lib/benchmark.rb', line 342

def initialize(width)
  @width = width
  @list = []
end

Instance Attribute Details

#listObject (readonly)

An array of 2-element arrays, consisting of label and block pairs.



362
363
364
# File 'lib/benchmark.rb', line 362

def list
  @list
end

#widthObject (readonly)

Length of the widest label in the #list.



365
366
367
# File 'lib/benchmark.rb', line 365

def width
  @width
end

Instance Method Details

#item(label = "", &blk) ⇒ Object Also known as: report

Registers the given label and block pair in the job list.

Raises:

  • (ArgumentError)


350
351
352
353
354
355
356
357
# File 'lib/benchmark.rb', line 350

def item(label = "", &blk) # :yield:
  raise ArgumentError, "no block" unless block_given?
  label = label.to_s
  w = label.length
  @width = w if @width < w
  @list << [label, blk]
  self
end