Module: Tins::Constant
- Included in:
- Module
- Defined in:
- lib/tins/dslkit.rb
Overview
A module that provides method-based DSL constant creation functionality. These constants are particularly useful for creating DSLs and configuration systems where symbolic names improve readability and maintainability.
Instance Method Summary collapse
-
#constant(name, value = name) ⇒ void
Creates a method-based constant named name that returns value.
Instance Method Details
#constant(name, value = name) ⇒ void
This method returns an undefined value.
Creates a method-based constant named name that returns value.
This method defines a method with the given name that always returns the specified value. The value is attempted to be frozen for immutability, though this will fail gracefully if freezing isn’t possible for the value.
337 338 339 340 |
# File 'lib/tins/dslkit.rb', line 337 def constant(name, value = name) value = value.freeze rescue value define_method(name) { value } end |