Start to make slots recursive

This commit is contained in:
2020-02-17 14:26:50 +07:00
parent b7df6f66f9
commit 21817b182e
11 changed files with 48 additions and 55 deletions

View File

@ -15,21 +15,24 @@ module SlotMachine
end
end
attr_reader :slots
# is an array of symbols, that specifies the first the object, and then the Slot.
# The first element is either a known type name (Capitalized symbol of the class name) ,
# or the symbol :message
# And subsequent symbols must be instance variables on the previous type.
# Examples: [:message , :receiver] or [:Space , :next_message]
def initialize( slots)
# The first in a possible chain of slots, that name instance variables in the
# previous object
attr_reader :slot
def initialize( slots )
raise "No slots #{object}" unless slots
slots = [slots] unless slots.is_a?(Array)
@slots = slots
first = slots.shift
@slot = Slot.new(first)
until(slots.empty?)
@slot.set_next( Slot.new( slots.shift ))
end
end
def to_s
names = [known_name] + @slots
"[#{names.join(', ')}]"
names = known_name.to_s
names += ".#{@slot}" if @slot
names
end