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 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)

    never to be filled



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

def self.array
  IMMUTABLE_EMPTY_ARRAY
end

.setSet

Returns 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)

    eternally empty



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

def self.set
  FrozenVoid::Set.new
end

.stringString

Returns 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)

    forever bereft of character



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

def self.string
  IMMUTABLE_EMPTY_STRING
end