Module: Tins::ConstantMaker

Defined in:
lib/tins/dslkit.rb

Overview

This module enables dynamic constant resolution by converting missing constant references into symbols. When a constant is not found, instead of raising NameError, the constant name is returned as a symbol. This is particularly useful for creating DSLs, configuration systems, and symbolic interfaces.

Examples:

Basic usage with missing constants

class MyClass
  extend Tins::ConstantMaker
end

# Missing constants return their names as symbols
MyClass.const_get(:UNKNOWN_CONSTANT)  # => :UNKNOWN_CONSTANT

Instance Method Summary collapse

Instance Method Details

#const_missing(id) ⇒ Symbol

Handles missing constant references by returning the constant name as a symbol.

This method is called when Ruby cannot find a constant in the current namespace. Instead of raising a NameError, it returns the constant name as a symbol, enabling symbolic constant handling throughout the application.

Parameters:

  • id (Symbol)

    The missing constant name

Returns:

  • (Symbol)

    The constant name as a symbol



563
564
565
# File 'lib/tins/dslkit.rb', line 563

def const_missing(id)
  id
end