Merge in a hash containing constant values. Arrays will be resolved as colors in RGBA or RGB format.

 @param [Hash<Symbol => Object>] constants_hash
336111
def merge_constants!(constants_hash)
      constants_hash.each_pair do |name, value|
        @constants[name] = case value
        when Array
          case value.size
          when 3 then Gosu::Color.rgb(*value)
          when 4 then Gosu::Color.rgba(*value)
          else
            raise "Colors must be in 0..255, RGB or RGBA array format"
          end
        else
          value
        end
      end

      self
    end
687216
def merge_conditions(conditions)
      @conditions = Conditions::Operation.new(:and) << @conditions unless @conditions.nil?

      conditions.compact!
      conditions.each do |condition|
        case condition
          when Conditions::AbstractOperation, Conditions::AbstractComparison
            add_condition(condition)

          when Hash
            condition.each { |key, value| append_condition(key, value) }

          when Array
            statement, *bind_values = *condition
            raw_condition = [ statement ]
            raw_condition << bind_values if bind_values.size > 0
            add_condition(raw_condition)
            @raw = true
        end
      end
    end
11173
def []=( color_tag, constants )
      @scheme[to_key(color_tag)] = constants.respond_to?(:map) ?
          constants.map { |c| to_constant(c) }.join : to_constant(constants)
    end
178287
def enum_constants
      constants.select { |constant|
        value = const_get constant
        value.is_a? ProgneTapera::EnumItem
      }
    end
1329619
def symbolize_keys(hash)
      hash.inject({}){|result, (key, value)|
        new_key = case key
          when String then key.to_sym
          else key
          end
        new_value = case value
          when Hash then symbolize_keys(value)
          else value
          end
        result[new_key] = new_value
        result
      }
    end
211252
def merge_id_hashes_helper(hash, array_of_refs, src, path = [])
      ref = array_of_refs.shift
      field = hash[ref]

      if array_of_refs.empty? && field
        value = value_from_hash(src, path + [ref])
        if value.is_a?(Array)
          hash[ref] = (field + value).uniq
        else
          hash.delete(ref)
        end
      else
        case field
        when Array
          field.each_with_index do |f, index|
            merge_id_hashes_helper(f, array_of_refs.dup, src, path + [ref, index])
          end
        when Hash
          merge_id_hashes_helper(field, array_of_refs, src, path + [ref])
        end
      end
    end
707861
def to_constant( v )
      v = v.to_s.upcase
      ColorScheme.const_get(v) if (ColorScheme.const_defined?(v, false) rescue ColorScheme.const_defined?(v))
    end
748997
def merge(other)
      old_attributes = attributes
      other_attributes = other.is_a?(Hash) ? other : other.attributes

      old_attributes.merge!(other_attributes) do |key, old_value, new_value|
        case key
        when :clusters, :contexts, :users
          old_value + new_value.reject do |new_mapping|
            old_value.any? { |old_mapping| old_mapping[:name] == new_mapping[:name] }
          end
        else
          case old_value
          when Array
            (old_value + new_value).uniq
          when Hash
            old_value.merge(new_value) do |_key, inner_old_value, inner_new_value|
              inner_old_value.nil? ? inner_new_value : inner_old_value
            end
          when NilClass
            new_value
          else
            warn "key is #{key} old val is #{old_value.inspect} and new val is #{new_value.inspect}"
            old_value
          end
        end
      end

      self.class.new(old_attributes)
    end
653254
def merge_color_configs(first, second):
    
    # We have to get the desired values first and simultaneously, as nametuple
    # is immutable.
    pound = get_priority(first.pound, second.pound, None)
    heading = get_priority(first.heading, second.heading, None)
    code = get_priority(first.code, second.code, None)
    backticks = get_priority(first.backticks, second.backticks, None)
    prompt = get_priority(first.prompt, second.prompt, None)
    pound_reset = get_priority(
        first.pound_reset,
        second.pound_reset,
        None
    )
    heading_reset = get_priority(
        first.heading_reset,
        second.heading_reset,
        None
    )
    code_reset = get_priority(
        first.code_reset,
        second.code_reset,
        None
    )
    backticks_reset = get_priority(
        first.backticks_reset,
        second.backticks_reset,
        None
    )
    prompt_reset = get_priority(
        first.prompt_reset,
        second.prompt_reset,
        None
    )

    result = ColorConfig(
        pound=pound,
        heading=heading,
        code=code,
        backticks=backticks,
        prompt=prompt,
        pound_reset=pound_reset,
        heading_reset=heading_reset,
        code_reset=code_reset,
        backticks_reset=backticks_reset,
        prompt_reset=prompt_reset
    )

    return result
613036
def compact_of(values = {}, path = KeyPath.new)
        result = {}
        values.each_with_index do |(i, v)|
          path.move_to(i)
          if v.is_a?(Hash)
            result.merge!(compact_of(v, path))
          else
            result[path.to_s] = v
          end
          path.leave
        end
        result
      end
1034869
def symbolize_keys(hash)
      hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
    end
718009
def colors_from_params(match, params)
      case params
      when Hash then colors_from_hash(match, params)
      when Symbol then color_from_symbol(match, params)
      end
    end
847220
def symbolize_keys(hash)
      hash = hash.to_hash
      if hash.respond_to?(:symbolize_keys)
        hash.symbolize_keys
      else
        hash.inject({}) do |new_hash, (key, value)|
          new_hash[symbolize_key(key)] = value
          new_hash
        end
      end
    end
437945
def deep_merge!(other_hash)
      other_hash.each_pair do |k,v|
        tv = self[k]
        self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? self.class.new(tv).deep_merge(v) : v
      end
      self
    end
679954
def symbolize_hash_keys(hash)
      hash.inject({}) do |new_hash, (key, value)|
        new_hash[(key.to_sym rescue key) || key] = value
        new_hash
      end
      hash
    end
1351165
def combine_diffs(diff_one, diff_two)
      Hash.new { |hash, key| hash[key] = [[], []] }.tap do |combined_diff|
        diff_one.each do |change|
          combined_diff[change.old_position].first << change
        end

        diff_two.each do |change|
          combined_diff[change.old_position].last << change
        end
      end
    end
1322047
def merge_texts!(hash, element)
      text_children = texts(element)
      if text_children.join.empty?
        hash
      else
        # must use value to prevent double-escaping
        merge!(hash, CONTENT_KEY, text_children.join)
      end
    end