Class: Mongory::Utils::SingletonBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/mongory/utils/singleton_builder.rb

Overview

A singleton placeholder object used to represent special sentinel values.

Used in situations where nil is a valid value and cannot be used as a marker. Typically used for internal constants like NOTHING or KEY_NOT_FOUND.

Examples:

NOTHING = SingletonBuilder.new('NOTHING')
value == NOTHING  # => true if placeholder

Direct Known Subclasses

Converters::AbstractConverter, Debugger

Instance Method Summary collapse

Constructor Details

#initialize(label, &block) ⇒ SingletonBuilder

Returns a new instance of SingletonBuilder.

Parameters:

  • label (String)

    a human-readable label for the marker



15
16
17
18
# File 'lib/mongory/utils/singleton_builder.rb', line 15

def initialize(label, &block)
  @label = label
  instance_eval(&block) if block_given?
end

Instance Method Details

#inspectString

Returns formatted label.

Returns:

  • (String)

    formatted label



21
22
23
# File 'lib/mongory/utils/singleton_builder.rb', line 21

def inspect
  "#<#{@label}>"
end

#to_sString

Returns formatted label.

Returns:

  • (String)

    formatted label



26
27
28
# File 'lib/mongory/utils/singleton_builder.rb', line 26

def to_s
  "#<#{@label}>"
end