Class: Lich::Common::TagList

Inherits:
Array
  • Object
show all
Defined in:
documented/common/map/map_base.rb

Overview

An Array of tag names that tells its owning Map class to drop the tag index whenever the list is structurally mutated. Stored names are frozen copies, so renaming a tag in place raises rather than silently leaving the index describing the old name. Reads are plain Array reads with no added indirection.

Constant Summary collapse

NON_BANG_MUTATORS =

Array mutators that do not end in a bang. This is a closed set, unlike the bang methods, which are derived below so that a mutator added by a future Ruby is covered without editing this list.

%i[
  << []= append clear concat delete delete_at delete_if fill insert
  keep_if pop prepend push replace shift unshift
].freeze
MUTATORS =

Every Array method that changes the receiver's contents.

(
  Array.public_instance_methods(false).select { |name| name.to_s.end_with?('!') } +
  NON_BANG_MUTATORS
).uniq.freeze

Instance Method Summary collapse

Constructor Details

#initialize(contents = nil, owner = nil) ⇒ TagList

Returns a new instance of TagList.

Parameters:

  • contents (Array, nil) (defaults to: nil)

    initial tag names

  • owner (Class, nil) (defaults to: nil)

    Map class notified on mutation



124
125
126
127
128
129
130
131
# File 'documented/common/map/map_base.rb', line 124

def initialize(contents = nil, owner = nil)
  super()
  # Order matters: concat is an intercepted mutator, so the initial fill
  # has to happen while @owner is still nil. Construction must not
  # invalidate the index, or a full map load would fire once per room.
  concat(contents.to_a) unless contents.nil?
  @owner = owner
end