Module: MTK::Lang::PseudoConstants

Included in:
Durations, Intensities, Intervals
Defined in:
lib/mtk/lang/pseudo_constants.rb

Overview

Extension for modules that want to define pseudo-constants (constant-like values with lower-case names)

Instance Method Summary collapse

Instance Method Details

#define_constant(name, value) ⇒ nil

Define a module method and module function (available both through the module namespace and as a mixin method), to provide a constant with a lower-case name.

Parameters:

  • name (Symbol)

    the name of the pseudo-constant

  • value (Object)

    the value of the pseudo-constant

Returns:

  • (nil)


13
14
15
16
17
18
19
20
21
22
# File 'lib/mtk/lang/pseudo_constants.rb', line 13

def define_constant name, value
  if name[0..0] =~ /[A-Z]/
    const_set name, value # it's just a normal constant
  else
    # the pseudo-constant definition is the combination of a method and module_function:
    define_method(name) { value }
    module_function name
  end
  nil
end