diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/instance_variables.rb | 8 | ||||
-rw-r--r-- | activesupport/test/core_ext/object_and_class_ext_test.rb | 7 |
3 files changed, 17 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 737e60cda8..1546dfb8c0 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Backport Object#instance_variable_defined? for Ruby < 1.8.6. [Jeremy Kemper] + * BufferedLogger#add doesn't modify the message argument. #9702 [eigentone] * Added ActiveSupport::BufferedLogger as a duck-typing alternative (albeit with no formatter) to the Ruby Logger, which provides a very nice speed bump (inspired by Ezra's buffered logger) [DHH] diff --git a/activesupport/lib/active_support/core_ext/object/instance_variables.rb b/activesupport/lib/active_support/core_ext/object/instance_variables.rb new file mode 100644 index 0000000000..72eaed70b6 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/object/instance_variables.rb @@ -0,0 +1,8 @@ +class Object + # Available in 1.8.6 and later. + unless respond_to?(:instance_variable_defined?) + def instance_variable_defined?(variable) + instance_variables.include?(variable.to_s) + end + end +end 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 f7e2cc4056..5e6144d64c 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -177,6 +177,13 @@ class ObjectInstanceVariableTest < Test::Unit::TestCase @source.instance_variable_set(:@baz, 'baz') end + def test_instance_variable_defined + assert @source.instance_variable_defined?('@bar') + assert @source.instance_variable_defined?(:@bar) + assert !@source.instance_variable_defined?(:@foo) + assert !@source.instance_variable_defined?('@foo') + end + def test_copy_instance_variables_from_without_explicit_excludes assert_equal [], @dest.instance_variables @dest.copy_instance_variables_from(@source) |