Sha256: 8ff30a1a0269fd0c5ead1eee7d47338eafcc1d29e3aff58ab49d535a391e3c28

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

class Shoes
  class SlotContents < SimpleDelegator
    include Common::Inspect

    def initialize
      @contents         = []
      @prepending       = false
      @prepending_index = 0
      super(@contents)
    end

    def prepending?
      @prepending
    end

    def add_element(element)
      if @prepending
        prepend_element element
      else
        append_element element
      end
    end

    def prepend
      @prepending_index = 0
      @prepending = true
      yield if block_given?
      @prepending = false
    end

    def clear
      # reverse_each is important as otherwise we always miss to delete one
      # element
      @contents.reverse_each(&:remove)
      @contents.clear
    end

    private

    def inspect_details
      " @size=#{size} @prepending=#{@prepending} @prepending_index=#{@prepending_index}"
    end

    def append_element(element)
      @contents << element
    end

    def prepend_element(element)
      @contents.insert @prepending_index, element
      @prepending_index += 1
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shoes-core-4.0.0.pre8 lib/shoes/slot_contents.rb
shoes-core-4.0.0.pre7 lib/shoes/slot_contents.rb