Class: Benchmark::Job
- Inherits:
-
Object
- Object
- Benchmark::Job
- Defined in:
- lib/benchmark.rb,
lib/railsbench/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
-
#list ⇒ Object
readonly
An array of 2-element arrays, consisting of label and block pairs.
-
#width ⇒ Object
readonly
Length of the widest label in the #list, plus one.
Instance Method Summary collapse
-
#initialize(width) ⇒ Job
constructor
Returns an initialized Job instance.
-
#item(label = "", &blk) ⇒ Object
(also: #report)
Registers the given label and block pair in the job list.
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.
331 332 333 334 |
# File 'lib/benchmark.rb', line 331 def initialize(width) @width = width @list = [] end |
Instance Attribute Details
#list ⇒ Object (readonly)
An array of 2-element arrays, consisting of label and block pairs.
351 352 353 |
# File 'lib/benchmark.rb', line 351 def list @list end |
#width ⇒ Object (readonly)
Length of the widest label in the #list, plus one.
354 355 356 |
# File 'lib/benchmark.rb', line 354 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.
339 340 341 342 343 344 345 346 |
# File 'lib/benchmark.rb', line 339 def item(label = "", &blk) # :yield: raise ArgmentError, "no block" unless block_given? label.concat ' ' w = label.length @width = w if @width < w @list.push [label, blk] self end |