Module: FrozenVoid

Defined in:
lib/frozen_void.rb

Overview

A source of unalterable emptiness.

Constant Summary collapse

IMMUTABLE_EMPTY_SET =
Set.new.freeze
IMMUTABLE_EMPTY_ARRAY =
[].freeze
IMMUTABLE_EMPTY_STRING =
"".freeze

Class Method Summary collapse

Class Method Details

.arrayArray

Returns an Array never to be filled.

Examples:

is empty

an_array = FrozenVoid.array
an_array.empty? #=> true

cannot be added to

an_array = FrozenVoid.array
an_array.push(:warmth) #=> raise FrozenError, "can't modify frozen Array: []"

is the same object as some other array from the void

an_array = FrozenVoid.array
another_array = FrozenVoid.array
an_array.equal?(another_array) #=> true

Returns:

  • (Array)

    an Array never to be filled



38
39
40
# File 'lib/frozen_void.rb', line 38

def self.array
  IMMUTABLE_EMPTY_ARRAY
end

.setSet

Returns a Set eternally empty.

Examples:

is empty

a_set = FrozenVoid.set
a_set.empty? #=> true

cannot be added to

a_set = FrozenVoid.set
a_set.add(:warmth) #=> raise FrozenError, "can't modify frozen Hash: {}"

is the same object as some other set from the void

a_set = FrozenVoid.set
another_set = FrozenVoid.set
a_set.equal?(another_set) #=> true

Returns:

  • (Set)

    a Set eternally empty



20
21
22
# File 'lib/frozen_void.rb', line 20

def self.set
  IMMUTABLE_EMPTY_SET
end

.stringString

Returns a String forever bereft of character.

Examples:

is empty

a_string = FrozenVoid.string
a_string.empty? #=> true

cannot be modified

a_string = FrozenVoid.string
a_string.upcase! #=> raise FrozenError, "can't modify frozen String: \"\""

is the same object as some other string from the void

a_string = FrozenVoid.string
another_string = FrozenVoid.string
a_string.equal?(another_string) #=> true

Returns:

  • (String)

    a String forever bereft of character



56
57
58
# File 'lib/frozen_void.rb', line 56

def self.string
  IMMUTABLE_EMPTY_STRING
end