Sha256: 1967c550132502ebe47d894a89709d6c09434b2605fe98e5d56e7fa96159e4ec
Contents?: true
Size: 1.08 KB
Versions: 3
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true module LazyLazer # Utility methods. # @api private module Utilities # Get a value from a hash, calling the default if needed. # @param [Hash] source the hash to lookup # @param [Symbol] key the key to lookup # @param [Proc, Object] default the default value or Proc to call # @return the object or the default value def self.lookup_default(source, key, default) return source[key] if source.key?(key) return default.call if default.is_a?(Proc) default end # Transforms a value using a "transformer" supplied using :with. # @param [Object] value the value to transform # @param [nil, Symbol, Proc] transformer the transformation method # @param [Object] context the context to run the proc in # @return [Object] the result of applying the transformation to the value def self.transform_value(value, transformer) case transformer when nil value when Symbol value.public_send(transformer) when Proc transformer.call(value) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
lazy_lazer-0.2.0 | lib/lazy_lazer/utilities.rb |
lazy_lazer-0.1.1 | lib/lazy_lazer/utilities.rb |
lazy_lazer-0.1.0 | lib/lazy_lazer/utilities.rb |