💎 CRYSTAL GEM DIFFICULTY: Apprentice Creational

The Singleton: The World Stone

Ensuring a class has only one instance, and providing a global point of access to it.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Abjuration // Core Binding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CRYSTAL PATTERN //
class WorldStone
  # The magical core instance is cached upon first use
  @@instance : WorldStone?

  property mana_level : Int32

  private def initialize
    @mana_level = 9999
    puts "The World Stone awakens from its long slumber."
  end

  def self.instance : WorldStone
    @@instance ||= new
  end

  def siphon_mana(amount : Int32)
    @mana_level -= amount
    puts "Siphoned #{amount} mana. Remaining: #{@mana_level}"
  end
end

stone1 = WorldStone.instance
stone1.siphon_mana(100)

stone2 = WorldStone.instance
stone2.siphon_mana(300)

puts "Both mages are drawing from the same stone: #{stone1.same?(stone2)}"

The Singleton is the ultimate anchor—a World Stone from which all mages in the realm draw their power. By restricting instantiation, we guarantee that all threads and fibers reference the exact same crystal, preventing chaotic splits in the world’s underlying mana supply.

Runic Tags: #creational #singleton #crystal #world-stone