module Dry::Core::Constants
A list of constants you can use to avoid memory allocations or identity checks.
@example Just include this module to your class or module
class Foo include Dry::Core::Constants def call(value = EMPTY_ARRAY) value.map(&:to_s) end end
@api public
Constants
- EMPTY_ARRAY
An empty array
- EMPTY_HASH
An empty hash
- EMPTY_OPTS
An empty list of options
- EMPTY_SET
An empty set
- EMPTY_STRING
An empty string
- IDENTITY
Identity function
- Undefined
A special value you can use as a default to know if no arguments were passed to the method
@example
def method(value = Undefined) if Undefined.equal?(value) puts 'no args' else puts value end end
Public Class Methods
included(base)
click to toggle source
Calls superclass method
# File lib/dry/core/constants.rb, line 108 def self.included(base) super constants.each do |const_name| base.const_set(const_name, const_get(const_name)) end end