Method: Vanguard.singleton_constant

Defined in:
lib/vanguard.rb

.singleton_constant(klass, name, &block) ⇒ self

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.

Define constant singleton class

Parameters:

  • klass (Class)
  • name (Symbol)

Returns:

  • (self)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vanguard.rb', line 25

def self.singleton_constant(klass, name, &block)
  subclass = Class.new(klass) do
    # Return inspection string
    #
    # @return [String]
    #
    # @api private
    #
    def inspect
      klass = self.class
      "#{klass.superclass.name}::#{klass.name}".freeze
    end
  end
  subclass.class_eval(&block)
  klass.const_set(name, subclass.new)
  self
end