aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/object/instance_variables.rb4
-rw-r--r--activesupport/test/core_ext/object_and_class_ext_test.rb4
2 files changed, 8 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 e07eb76c1d..57276135c4 100644
--- a/activesupport/lib/active_support/core_ext/object/instance_variables.rb
+++ b/activesupport/lib/active_support/core_ext/object/instance_variables.rb
@@ -13,6 +13,10 @@ class Object
end
end
+ def instance_variable_names
+ instance_variables.map(&:to_s)
+ end
+
def copy_instance_variables_from(object, exclude = []) #:nodoc:
exclude += object.protected_instance_variables if object.respond_to? :protected_instance_variables
diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb
index f885d94be3..09a86721dd 100644
--- a/activesupport/test/core_ext/object_and_class_ext_test.rb
+++ b/activesupport/test/core_ext/object_and_class_ext_test.rb
@@ -182,6 +182,10 @@ class ObjectInstanceVariableTest < Test::Unit::TestCase
@source.instance_variable_set(:@baz, 'baz')
end
+ def test_instance_variable_names
+ assert_equal %w(@bar @baz), @source.instance_variable_names.sort
+ end
+
def test_instance_variable_defined
assert @source.instance_variable_defined?('@bar')
assert @source.instance_variable_defined?(:@bar)