Makes slots linked list

slots used to ba an array of symbols
Now we have an object for each slot, that holds the name and the next_slot
relatively easy change, though quite broad
This commit is contained in:
2020-02-17 14:29:45 +07:00
parent 93103d551f
commit c1679bd6ff
16 changed files with 69 additions and 49 deletions

View File

@ -18,11 +18,13 @@ module SlotMachine
attr_reader :name , :next_slot
# initialize with just the name of the slot. Add more to the chain with set_next
def initialize( name )
raise "No name" unless name
@name = name
@name = name
end
#set the next_slot , but always at the end of the chain
def set_next(slot)
if(@next_slot)
@next_slot.set_next(slot)
@ -31,12 +33,18 @@ module SlotMachine
end
end
# return the length of chain, ie 1 plus however many more next_slots there are
def length
return 1 unless @next_slot
1 + @next_slot.length
end
# name of all the slots, with dot syntax
def to_s
names = name.to_s
names += ".#{@next_slot}" if @next_slot
names
end
end
end