The Iterator
Traversing the infinite crypts of fallen thralls without exposing the horrifying internal structure of the catacombs.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Necromancy // Traversal
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// DYNAMIC RUBY BLOOD MAGIC //
class ThrallCrypt
include Enumerable
def initialize
@coffins = []
end
def add_thrall(name)
@coffins << name
end
def each(&block)
@coffins.each(&block)
end
end
# Usage:
# crypt = ThrallCrypt.new
# crypt.add_thrall("Bob the Bleeder")
# crypt.add_thrall("Alice the Anemic")
# crypt.map { |thrall| "Arise, #{thrall}!" }
The Iterator provides a way to access elements of an aggregate object sequentially. In Ruby, including the Enumerable module and defining an each method instantly grants the ThrallCrypt the full power of Ruby’s functional iteration tools (map, select, reject).
Runic Tags:
#ruby
#design-pattern
#iterator
#blood-magic