Class: Naught::NullClassBuilder::Commands::Singleton Private

Inherits:
Naught::NullClassBuilder::Command show all
Defined in:
lib/naught/null_class_builder/commands/singleton.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Turns the null class into a Singleton

API:

  • private

Instance Attribute Summary

Attributes inherited from Naught::NullClassBuilder::Command

#builder

Instance Method Summary collapse

Methods inherited from Naught::NullClassBuilder::Command

#initialize

Constructor Details

This class inherits a constructor from Naught::NullClassBuilder::Command

Instance Method Details

#callvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Install Singleton behavior on the null class

API:

  • private



14
15
16
17
18
19
20
21
# File 'lib/naught/null_class_builder/commands/singleton.rb', line 14

def call
  defer_class do |klass|
    klass.include(::Singleton)
    klass.singleton_class.undef_method(:get)
    klass.define_singleton_method(:get) { |*| instance }
    %i[dup clone].each { |name| klass.define_method(name) { self } }
  end
end