Module: Xavier::MutationStrategies::InstanceCopy Private

Defined in:
lib/xavier/mutation_strategies/instance_copy.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Copies the instance variables from one object to other.

API:

  • private

Class Method Summary collapse

Class Method Details

.copy(from:, to:) ⇒ Array<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Copies the instance variables from one object to other.

Parameters:

  • An object where the state will be copied from.

  • An object where the state will be copied to.

Returns:

  • A list of variable names that were copied.

API:

  • private



15
16
17
18
# File 'lib/xavier/mutation_strategies/instance_copy.rb', line 15

def self.copy(from:, to:)
  vars = from.instance_variables.map(&:to_s)
  vars.each { |name| to.instance_variable_set(name, from.instance_variable_get(name)) }
end