Recursively merges Hash (or any Object that can be converted to a Hash),
 Array and attributes that have implemented an :attribute_add method.
506713
def deep_merge(arg1, arg2, key=nil)
      # Attempt deep merge if the two arguments are
      # instances of the same class.
      if arg1.class == arg2.class
        # Preserve arg1's :code and :name.
        if (not key.nil?) and [:code, :name].include? key.to_sym
          return arg1
        # Recursively call deep merge for Hash objects.
        elsif arg1.respond_to? :to_hash
          r = {}
          return arg1.to_hash.merge(arg2.to_hash) do |key, oldval, newval|
            r[key] = deep_merge(oldval, newval, key)
          end
        # Concatenate Arrays and return uniq elements.
        elsif arg1.instance_of? Array
          return arg1.concat(arg2).uniq
        # If Institutions responds to the :key_add method,
        # go ahead and use that to add the Objects together.
        elsif respond_to? "#{key}_add".to_sym
          return send "#{key}_add".to_sym, arg1, arg2
        end
      end
      # NOTE: Commenting this out since I'm not sure this is desirable functionality.
      # If the two args aren't the same class, but arg1 is
      # Array, append arg2 to arg1.
      # if arg1.instance_of? Array
      #   return arg1.dup<<arg2
      # end
      # We tried.
      # If all else fails just replace arg1 with arg2.
      return arg2
    end
280676
def merge_hashes(hashes)
      hashes.inject({}) { |n, h| n.weave(h, true) }
    end
187788
def add_line_hash(value_hash)
      @lines << value_hash
      if value_hash[:compound]
        value_hash.each do |key, value|
          if value_hash[:compound].include?(key)
            @attributes[key] = [] if @attributes[key].nil?
            @attributes[key] = [@attributes[key]] unless @attributes[key].is_a?(Array)
            @attributes[key] << value
          else
            @attributes[key] = value unless key == :compound || @attributes[key]
          end
        end
      else
        @attributes = value_hash.merge(@attributes)
      end
    end
754158
public function merge(array $attributes)
    {
        foreach ($attributes as $name => $value) {
            $this->add($name, $value);
        }
    }
1129591
def to_hash(obj=nil, methods:[], recursive: false, check: false, compact: false)
			return {} if obj.nil?
			obj||=self
			stack=[*obj]
			processed=[]
			klass=stack.first.class
			h={}
			while !stack.empty?
				obj=stack.shift
				next if processed.include?(obj)
				processed << obj
				attributes={}
				methods.each do |m|
					next if check and !obj.respond_to? m
					v=obj.public_send(m)
					attributes[m]=v
					if recursive
						vals=v.kind_of?(Enumerable) ? v.to_a.flatten : [v]
						vals.select! {|v| v.kind_of?(klass)}
						stack.concat(vals)
					end
				end
				attributes=attributes.values.first if compact and attributes.keys.length == 1
				h[obj]=attributes
			end
			h
		end
1118749
def add_attribute(name, value, options={})
      new_representor_hash = RepresentorHash.new(deep_dup(@representor_hash.to_h))
      new_representor_hash.attributes[name] = options.merge({value: value})
      RepresentorBuilder.new(new_representor_hash)
    end
1067382
def buffer_attributes_to_hash(attributes)
      '{' + attributes.inject([]) do |extend_map, (key, attribute)|
        extend_map << (
          ":\"#{key}\" => " + if key == :class
                                '[' + attribute.map do |exp|
                                  exp[@value]
                                end.join(', ') + ']'
                              else
                                attribute[@value]
                              end
        )
      end.join(', ') + '}'
    end
1368723
def update_attributes(attrs)
      if id = attrs.delete(:id)
        @id = id
      end
      attrs.each do |key, value|
        setter = :"#{key}="
        send(setter, value) if respond_to?(setter)
      end
    end
362630
def create(attributes_hash)
      #the tap method allows preconfigured methods and values to
      #be associated with the instance during instantiation while also automatically returning
      #the object after its creation is concluded.
      self.new.tap do |card|
        attributes_hash.each do |key, value|
          #sending the new instance the key name as a setter with the value
          card.send("#{key}=", value)
          #string interpolation is used as the method doesn't know the key name yet
          #but an = sign is implemented into the string in order to asssociate it as a setter
        end
        #saves the new instance into the database
        card.save
      end
    end
934724
def merge_attrs(list_of_attrs):
    
    result = DEFAULT_ATTRS

    for attr in list_of_attrs:
        result = Attrs(
            color=attr.color or result.color,
            bgcolor=attr.bgcolor or result.bgcolor,
            bold=attr.bold or result.bold,
            underline=attr.underline or result.underline,
            italic=attr.italic or result.italic,
            blink=attr.blink or result.blink,
            reverse=attr.reverse or result.reverse)

    return result
124743
def to_hash
      _new_hash= {}
      each do |key, value|
        _new_hash[convert_key(key)] = convert_value(value, for: :to_hash)
      end
      Hash.new(default).merge!(_new_hash)
    end
1166986
def merge_in(old)
      merge(@class_methods, old.class_methods)
      merge(@instance_methods, old.instance_methods)
      merge(@attributes, old.attributes)
      merge(@constants, old.constants)
      merge(@includes, old.includes)
      if @comment.nil? || @comment.empty?
        @comment = old.comment
      else
        unless old.comment.nil? or old.comment.empty? then
          @comment << SM::Flow::RULE.new
          @comment.concat old.comment
        end
      end
    end
690854
def merge(base_hash, derived_hash, **opts)
      result = base_hash.merge(derived_hash)
      keys_appearing_in_both = base_hash.keys & derived_hash.keys
      keys_appearing_in_both.each do |key|
        if opts[:unset_nil] && derived_hash[key].nil?
          result.delete(key)
        elsif base_hash[key].is_a?(Hash)
          result[key] = merge(base_hash[key], derived_hash[key], **opts)
        elsif should_union?(base_hash, key, opts[:inherit_mode])
          result[key] = base_hash[key] | derived_hash[key]
        elsif opts[:debug]
          warn_on_duplicate_setting(base_hash, derived_hash, key, opts)
        end
      end
      result
    end
1152198
def merge_attributes(attr1, attr2):
    

    new_d = copy.deepcopy(attr1)
    new_d.update(attr2)

    #all of attr2 key : values just overwrote attr1, fix it
    for k, v in new_d.items():
        if not isinstance(v, list):
            new_d[k] = [v]

    for k, v in six.iteritems(attr1):
        if k in attr2:
            if not isinstance(v, list):
                v = [v]
            new_d[k].extend(v)
    return dict((k, sorted(set(v))) for k, v in new_d.items())
138148
def attrs
      @attrs.inject({}) do |attrs, (key, value)|
        attrs.merge!(key => respond_to?(key) ? send(key) : value)
      end
    end
95636
def serialize_modified_attributes
    attr_hash = {}
    @modified_attributes.each_pair do |name,hash|
      attr_hash[name] = serialize_attribute(name,hash[:new])
    end
    attr_hash[:id] = serialize_id unless new?
    attr_hash
  end
221279
def merge_name_and_attributes(name, attributes_hash = {})
      # skip merging if no ids or classes found in name
      return name, attributes_hash unless name =~ /^(.+?)?([\.#].*)$/

      return $1 || "div", AttributeBuilder.merge_attributes!(
        Haml::Parser.parse_class_and_id($2), attributes_hash)
    end