Class: Shifty::Roster
- Inherits:
-
Object
- Object
- Shifty::Roster
- Extended by:
- Forwardable
- Defined in:
- lib/shifty/roster.rb
Instance Attribute Summary collapse
-
#workers ⇒ Object
readonly
Returns the value of attribute workers.
Instance Method Summary collapse
-
#initialize(workers = []) ⇒ Roster
constructor
A new instance of Roster.
- #pop ⇒ Object
- #push(worker) ⇒ Object (also: #<<)
- #shift ⇒ Object
- #unshift(worker) ⇒ Object
Constructor Details
#initialize(workers = []) ⇒ Roster
Returns a new instance of Roster.
9 10 11 12 13 14 |
# File 'lib/shifty/roster.rb', line 9 def initialize(workers = []) @workers = [] workers.each do |worker| push worker end end |
Instance Attribute Details
#workers ⇒ Object (readonly)
Returns the value of attribute workers.
7 8 9 |
# File 'lib/shifty/roster.rb', line 7 def workers @workers end |
Instance Method Details
#pop ⇒ Object
26 27 28 29 30 |
# File 'lib/shifty/roster.rb', line 26 def pop workers.pop.tap do |popped| popped.supply = nil end end |
#push(worker) ⇒ Object Also known as: <<
18 19 20 21 22 23 |
# File 'lib/shifty/roster.rb', line 18 def push(worker) if worker worker.supply = workers.last unless workers.empty? workers << worker end end |
#shift ⇒ Object
32 33 34 35 36 |
# File 'lib/shifty/roster.rb', line 32 def shift workers.shift.tap do workers.first.supply = nil end end |
#unshift(worker) ⇒ Object
38 39 40 41 |
# File 'lib/shifty/roster.rb', line 38 def unshift(worker) workers.first.supply = worker workers.unshift worker end |