aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/object/instance_variables.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/core_ext/object/instance_variables.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/object/instance_variables.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/instance_variables.rb b/activesupport/lib/active_support/core_ext/object/instance_variables.rb
index 72eaed70b6..e07eb76c1d 100644
--- a/activesupport/lib/active_support/core_ext/object/instance_variables.rb
+++ b/activesupport/lib/active_support/core_ext/object/instance_variables.rb
@@ -5,4 +5,18 @@ class Object
instance_variables.include?(variable.to_s)
end
end
+
+ def instance_values #:nodoc:
+ instance_variables.inject({}) do |values, name|
+ values[name.to_s[1..-1]] = instance_variable_get(name)
+ values
+ end
+ end
+
+ def copy_instance_variables_from(object, exclude = []) #:nodoc:
+ exclude += object.protected_instance_variables if object.respond_to? :protected_instance_variables
+
+ vars = object.instance_variables.map(&:to_s) - exclude.map(&:to_s)
+ vars.each { |name| instance_variable_set(name, object.instance_variable_get(name)) }
+ end
end