mirror of
https://github.com/github/rails.git
synced 2026-02-03 02:35:08 -05:00
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
This commit is contained in:
@@ -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 @@ 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)
|
||||
|
||||
Reference in New Issue
Block a user