Permalink
Browse files

Backport Object#instance_variable_defined? for Ruby < 1.8.6.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7649 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 7974f47 commit d96e38be9992e0fe93668ab46d9442f702d370dd @jeremy jeremy committed Sep 27, 2007
View
@@ -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]
@@ -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
@@ -177,6 +177,13 @@ def setup
@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)

0 comments on commit d96e38b

Please sign in to comment.