Class: Forklift::Worker
- Inherits:
-
Object
- Object
- Forklift::Worker
- Defined in:
- lib/forklift/worker.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Instance Method Summary collapse
-
#==(other_nr) ⇒ Object
worker objects may be compared to just plain Integers.
-
#close ⇒ Object
:nodoc:.
-
#initialize(logger, number) ⇒ Worker
constructor
A new instance of Worker.
- #nr ⇒ Object
- #perform ⇒ Object
- #tick ⇒ Object
- #tick=(int) ⇒ Object
Constructor Details
#initialize(logger, number) ⇒ Worker
Returns a new instance of Worker.
6 7 8 9 10 11 12 |
# File 'lib/forklift/worker.rb', line 6 def initialize(logger, number) @i = 0 @number = number @tick = Time.now.to_i @logger = logger logger.debug "Worker #{number} spawned" end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
4 5 6 |
# File 'lib/forklift/worker.rb', line 4 def logger @logger end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
4 5 6 |
# File 'lib/forklift/worker.rb', line 4 def number @number end |
Instance Method Details
#==(other_nr) ⇒ Object
worker objects may be compared to just plain Integers
15 16 17 |
# File 'lib/forklift/worker.rb', line 15 def ==(other_nr) # :nodoc: @number == other_nr end |
#close ⇒ Object
:nodoc:
31 32 33 |
# File 'lib/forklift/worker.rb', line 31 def close # :nodoc: @tmp.close if @tmp end |
#nr ⇒ Object
27 28 29 |
# File 'lib/forklift/worker.rb', line 27 def nr @number end |
#perform ⇒ Object
35 36 37 38 39 |
# File 'lib/forklift/worker.rb', line 35 def perform @i += 1 logger.info "Working #{@i}" sleep 5 end |
#tick ⇒ Object
23 24 25 |
# File 'lib/forklift/worker.rb', line 23 def tick @tick end |
#tick=(int) ⇒ Object
19 20 21 |
# File 'lib/forklift/worker.rb', line 19 def tick=(int) @tick = int end |