Class: Naught::NullClassBuilder::Commands::Singleton Private
- Inherits:
-
Naught::NullClassBuilder::Command
- Object
- Naught::NullClassBuilder::Command
- Naught::NullClassBuilder::Commands::Singleton
- 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
Instance Attribute Summary
Attributes inherited from Naught::NullClassBuilder::Command
Instance Method Summary collapse
-
#call ⇒ void
private
Install Singleton behavior on the null class.
Methods inherited from Naught::NullClassBuilder::Command
Constructor Details
This class inherits a constructor from Naught::NullClassBuilder::Command
Instance Method Details
#call ⇒ void
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
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 |