Torsten Rüger
c1679bd6ff
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
55 lines
1.1 KiB
Ruby
55 lines
1.1 KiB
Ruby
module SlotMachine
|
|
|
|
class Slotted
|
|
|
|
def self.for(object , slots)
|
|
case object
|
|
when :message
|
|
SlottedMessage.new(slots)
|
|
when Constant
|
|
SlottedConstant.new(object , slots)
|
|
when Parfait::Object , Risc::Label
|
|
SlottedObject.new(object , slots)
|
|
else
|
|
raise "not supported type #{object}:#{object.class}"
|
|
end
|
|
end
|
|
|
|
# The first in a possible chain of slots, that name instance variables in the
|
|
# previous object
|
|
attr_reader :slots
|
|
|
|
def initialize( slots )
|
|
raise "No slots #{object}" unless slots
|
|
slots = [slots] unless slots.is_a?(Array)
|
|
first = slots.shift
|
|
return unless first
|
|
@slots = Slot.new(first)
|
|
until(slots.empty?)
|
|
@slots.set_next( Slot.new( slots.shift ))
|
|
end
|
|
end
|
|
|
|
def slots_length
|
|
return 0 unless @slots
|
|
1 + @slots.length
|
|
end
|
|
|
|
def set_next(slot)
|
|
if(@slots)
|
|
@slots.set_next(slot)
|
|
else
|
|
@slots = slot
|
|
end
|
|
end
|
|
|
|
def to_s
|
|
names = known_name.to_s
|
|
names += ".#{@slots}" if @slots
|
|
names
|
|
end
|
|
|
|
|
|
end
|
|
end
|