Actually replace the object

@author   Jelle De Loecker   <jelle@develry.be>
@since    0.1.0
@version  1.0.11
4347
function replaceObject(dryReplacer, value, chain, flags, is_wrap, holder, path, value_paths, key) {

	var class_name,
	    seen_path,
	    new_value,
	    replaced,
	    is_array,
	    keys,
	    last,
	    temp,
	    len,
	    i;

	if (typeof value.constructor == 'function') {
		class_name = value.constructor.name;
	} else {
		class_name = 'Object';
	}

	// See if the chain needs popping
	while (len = chain.length) {

		// If the current object at the end of the chain does not
		// match the current holder, move one up
		// Don't mess with the chain if this is a wrap object
		if (!is_wrap && holder !== chain[len-1]) {

			last = chain.pop();

			// Only pop the path if the popped object isn't a wrapper
			if (last && !last.__is_wrap) {
				path.pop();
			}
		} else {
			break;
		}
	}

	// Has the object been seen before?
	seen_path = value_paths.get(value);

	if (seen_path) {

		// If the path is still an array,
		// turn it into a string now
		if (typeof seen_path != 'string') {

			// First iterate over the pieces and escape them
			for (i = 0; i < seen_path.length; i++) {
				if (seen_path[i].indexOf(special_char) > -1) {
					seen_path[i] = seen_path[i].replace(special_char_rg, safe_special_char);
				}
			}

			seen_path = special_char + seen_path.join(special_char);
			value_paths.set(value, seen_path);
		}

		// Replace the value with the path
		new_value = seen_path;

		// See if the new path is shorter
		len = 1;
		for (i = 0; i < path.length; i++) {
			len += 1 + path[i].length;
		}
		len += key.length;

		if (len < seen_path.length) {
			temp = seen_path;
			seen_path = path.slice(0);

			// The key of the current value still needs to be added
			seen_path.push(key);

			// First iterate over the pieces and escape them
			for (i = 0; i < seen_path.length; i++) {
				if (seen_path[i].indexOf(special_char) > -1) {
					seen_path[i] = seen_path[i].replace(special_char_rg, safe_special_char);
				}
			}

			seen_path = special_char + seen_path.join(special_char);
			value_paths.set(value, seen_path);

			// This entry still has to refer to the longer path,
			// otherwise it'll refer to itself
			seen_path = temp;
		}

		value = new_value;

		return value;
	}

	if (!flags.is_root && !is_wrap) {
		path.push(key);
	} else {
		flags.is_root = false;
	}

	// Make a copy of the current path array
	value_paths.set(value, path.slice(0));

	if (driers[class_name] != null) {
		value = driers[class_name].fnc(holder, key, value);

		value = {
			dry: class_name,
			value: value
		};

		if (driers[class_name].options.add_path !== false) {
			value.drypath = path.slice(0);
		}

		replaced = {'': value};
	} else if (class_name === 'RegExp' && value.constructor == RegExp) {
		value = {dry: 'regexp', value: value.toString()};
		replaced = {'': value};
	} else if (class_name === 'Date' && value.constructor == Date) {
		value = {dry: 'date', value: value.toISOString()};
		replaced = {'': value};
	} else if (typeof value.toDry === 'function') {
		temp = value;
		value = value.toDry();

		// If no path was supplied in the toDry,
		// get some more class information
		if (!value.path) {
			if (temp.constructor) {
				if (!value.namespace && temp.constructor.namespace) {
					value.namespace = temp.constructor.namespace;
				}

				if (!value.dry_class) {
					value.dry_class = temp.constructor.name;
				}
			}
		}

		value.dry = 'toDry';
		value.drypath = path.slice(0);
		replaced = {'': value};
	} else if (typeof value.toJSON === 'function') {
		value = value.toJSON();
		replaced = {'': value};
	} else {
		is_array = Array.isArray(value);
	}

	if (replaced) {
		// Push the replaced object on the chain
		chain.push(replaced);

		// Jsonify the replaced object
		value = dryReplacer(replaced, false, replaced['']);

		// At least one part of the path & chain will have
		// to be popped off. This is needed for toJSON calls
		// that return primitive values
		temp = chain.pop();

		// Don't pop off anything from the path if the last item
		// from the chain was a wrapper for an object,
		// because then it'll already be popped of
		if (!(temp && temp.__is_wrap && temp.__is_object)) {
			path.pop();
		}

		// Break out of the switch
		return value;
	}

	// Push this object on the chain
	chain.push(value);

	if (is_array) {
		new_value = [];

		for (i = 0; i < value.length; i++) {
			new_value[i] = dryReplacer(value, String(i), value[i]);
		}
	} else {
		new_value = recurseGeneralObject(dryReplacer, value);
	}

	value = new_value;

	return value;
}
1006856
private function prepareReplacements()
    {
        $usesString = '';
        foreach ($this->modelReplacements[':uses'] as $use) {
            $usesString .= 'use '.$use.';'.PHP_EOL;
        }
        $this->modelReplacements[':uses'] = $usesString;

        $this->modelReplacements[':implementations'] = ! empty($this->modelReplacements[':implementations']) ?
            'implements '.implode(', ', $this->modelReplacements[':implementations']) : '';

        $this->modelReplacements[':traits'] = ! empty($this->modelReplacements[':traits']) ?
            'use '.implode(', ', $this->modelReplacements[':traits']).';' : '';
    }
1214326
def replaceChild(self, newchild, oldchild):
		
		# .index() would use compare-by-value, we want
		# compare-by-id because we want to find the exact object,
		# not something equivalent to it.
		for i, childNode in enumerate(self.childNodes):
			if childNode is oldchild:
				self.childNodes[i].parentNode = None
				self.childNodes[i] = newchild
				newchild.parentNode = self
				self._verifyChildren(i)
				return newchild
		raise ValueError(oldchild)
1177890
function regenerateObject(root, holder, current, seen, retrieve, undry_paths, old, current_path) {

	var path,
	    temp,
	    key;

	for (key in current) {
		if (current.hasOwnProperty(key)) {
			// Only regenerate if it's not already seen
			if (!seen.get(current[key])) {
				path = current_path.slice(0);
				path.push(key);

				temp = regenerate(root, current, current[key], seen, retrieve, undry_paths, old, path);

				// @TODO: Values returned by `unDry` methods also get regenerated,
				// even though these could contain properties coming from somewhere else,
				// like live HTMLCollections. Assigning anything to that will throw an error.
				// This is a workaround to that proble: if the value is exactly the same,
				// it's not needed to assign it again, so it won't throw an error,
				// but it's not an ideal solution.
				if (temp !== current[key]) {
					current[key] = temp;
				}
			}
		}
	}

	return current;
}
191795
function applyChange(original, key, value) {
  if (value === undefined) {
    return Object.assign({}, original, key);
  }
  return Object.assign({}, original, { [key]: value });
}
968142
function patch(obj, properties) {
  var old = {};
  for (var name in properties) {
    old[name] = obj[name];
    obj[name] = properties[name];
  }
  return old;
}
1297614
def replacements
      nodes.reject { |node| method_order_correct?(node) }.each_with_object({}) do |node, obj|
        node_to_replace = nodes[expected_method_index(node)]

        obj[node] = {
          node => node_to_replace,
          node_to_replace => nodes[expected_method_index(node_to_replace)]
        }
      end
    end
346642
function rename(object, fromKey, toKey) {
  if ((0, _has2.default)(object, fromKey)) {
    object[toKey] = object[fromKey];
    delete object[fromKey];
  }
}
704071
def replace(self, parameters=_void, return_annotation=_void):
        

        if parameters is _void:
            parameters = self.parameters.values()

        if return_annotation is _void:
            return_annotation = self._return_annotation

        return type(self)(parameters, return_annotation=return_annotation)
969188
function( obj ){
      if( obj == null ){
        return obj;
      } if( $$.is.array(obj) ){
        return obj.slice();
      } else if( $$.is.plainObject(obj) ){
        return $$.util.clone( obj );
      } else {
        return obj;
      }
    }
277388
@Override
  public boolean replace    ( TypeK  key, TypeV  oldValue, TypeV newValue ) {
    return Objects.equals(putIfMatch( key, newValue, oldValue ), oldValue);
  }
784890
function replace(attrs = {}) {
  if (typeof document === 'undefined') {
    throw new Error('`feather.replace()` only works in a browser environment.');
  }

  const elementsToReplace = document.querySelectorAll('[data-feather]');

  Array.from(elementsToReplace).forEach(element =>
    replaceElement(element, attrs),
  );
}
1018732
protected function replaceRequestInstance()
    {
        \array_pop($this->requestStack);

        $this->container->instance('request', \end($this->requestStack));
    }
627813
function Replace()
	{
	global $ADODB_ASSOC_CASE;

		$db = $this->DB();
		if (!$db) {
			return false;
		}
		$table = $this->TableInfo();

		$pkey = $table->keys;

		foreach($table->flds as $name=>$fld) {
			$val = $this->$name;
			/*
			if (is_null($val)) {
				if (isset($fld->not_null) && $fld->not_null) {
					if (isset($fld->default_value) && strlen($fld->default_value)) {
						continue;
					}
					else {
						$this->Error("Cannot update null into $name","Replace");
						return false;
					}
				}
			}*/
			if (is_null($val) && !empty($fld->auto_increment)) {
				continue;
			}

			if (is_array($val)) {
				continue;
			}

			$t = $db->MetaType($fld->type);
			$arr[$name] = $this->doquote($db,$val,$t);
			$valarr[] = $val;
		}

		if (!is_array($pkey)) {
			$pkey = array($pkey);
		}

		if ($ADODB_ASSOC_CASE == 0) {
			foreach($pkey as $k => $v)
				$pkey[$k] = strtolower($v);
		}
		elseif ($ADODB_ASSOC_CASE == 1) {
			foreach($pkey as $k => $v) {
				$pkey[$k] = strtoupper($v);
			}
		}

		$ok = $db->Replace($this->_table,$arr,$pkey);
		if ($ok) {
			$this->_saved = true; // 1= update 2=insert
			if ($ok == 2) {
				$autoinc = false;
				foreach($table->keys as $k) {
					if (is_null($this->$k)) {
						$autoinc = true;
						break;
					}
				}
				if ($autoinc && sizeof($table->keys) == 1) {
					$k = reset($table->keys);
					$this->$k = $this->LastInsertID($db,$k);
				}
			}

			$this->_original = $valarr;
		}
		return $ok;
	}
300614
function replacer(key, value) {
        if (!value) {
            return value;
        }

        const type = typeof value;

        if (type === 'object') {
            if (isRegExp(value)) {
                return '@__R-' + UID + '-' + (regexps.push(value) - 1) + '__@';
            }

            return value;
        }

        if (type === 'function') {
            return '@__F-' + UID + '-' + (functions.push(value) - 1) + '__@';
        }

        return value;
    }
1217456
function(newNode, oldNode) {
        newNode = newNode.get ? newNode.get('element') : newNode;
        oldNode = oldNode.get ? oldNode.get('element') : oldNode;
        return this.get('element').replaceChild(newNode, oldNode);
    }
740745
def replace(self):
        

        replacement = self._tw.tasks.get(uuid=self._uuid)
        self.__class__ = replacement.__class__
        self.__dict__ = replacement.__dict__