-
Notifications
You must be signed in to change notification settings - Fork 0
/
disk.rb
30 lines (25 loc) · 792 Bytes
/
disk.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Disk
attr_reader :position
def initialize(values)
@values = values
@position = Position.new
end
# Move the disk by incrementing it's position's offset.
def shift
return @position.shift
end
# Read the values of the disk. Shift the default values to the right
# according to the disk's position's current offset. This method
# never modifies the values attribute in order to be able to always
# keep a copy of the default values (when the disk's position's
# offset is 0).
def values
result = @values.clone
@position.offset.times { result.unshift result.pop }
return result
end
# Read the current value of a tab.
def value(offset)
return values[offset]
end
end