1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove unused method

This commit is contained in:
Santiago Pastorino 2010-11-10 16:56:01 -02:00
parent b961c6c158
commit c20838596b
2 changed files with 0 additions and 62 deletions

View file

@ -30,35 +30,4 @@ class Object
else else
alias_method :instance_variable_names, :instance_variables alias_method :instance_variable_names, :instance_variables
end end
# Copies the instance variables of +object+ into +self+.
#
# Instance variable names in the +exclude+ array are ignored. If +object+
# responds to <tt>protected_instance_variables</tt> the ones returned are
# also ignored. For example, Rails controllers implement that method.
#
# In both cases strings and symbols are understood, and they have to include
# the at sign.
#
# class C
# def initialize(x, y, z)
# @x, @y, @z = x, y, z
# end
#
# def protected_instance_variables
# %w(@z)
# end
# end
#
# a = C.new(0, 1, 2)
# b = C.new(3, 4, 5)
#
# a.copy_instance_variables_from(b, [:@y])
# # a is now: @x = 3, @y = 1, @z = 2
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 end

View file

@ -82,37 +82,6 @@ class ObjectInstanceVariableTest < Test::Unit::TestCase
assert_equal %w(@bar @baz), @source.instance_variable_names.sort assert_equal %w(@bar @baz), @source.instance_variable_names.sort
end end
def test_copy_instance_variables_from_without_explicit_excludes
assert_equal [], @dest.instance_variables
@dest.copy_instance_variables_from(@source)
assert_equal %w(@bar @baz), @dest.instance_variables.sort.map(&:to_s)
%w(@bar @baz).each do |name|
assert_equal @source.instance_variable_get(name).object_id,
@dest.instance_variable_get(name).object_id
end
end
def test_copy_instance_variables_from_with_explicit_excludes
@dest.copy_instance_variables_from(@source, ['@baz'])
assert !@dest.instance_variable_defined?('@baz')
assert_equal 'bar', @dest.instance_variable_get('@bar')
end
def test_copy_instance_variables_automatically_excludes_protected_instance_variables
@source.instance_variable_set(:@quux, 'quux')
class << @source
def protected_instance_variables
['@bar', :@quux]
end
end
@dest.copy_instance_variables_from(@source)
assert !@dest.instance_variable_defined?('@bar')
assert !@dest.instance_variable_defined?('@quux')
assert_equal 'baz', @dest.instance_variable_get('@baz')
end
def test_instance_values def test_instance_values
object = Object.new object = Object.new
object.instance_variable_set :@a, 1 object.instance_variable_set :@a, 1