Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c2083859
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c2083859
编写于
11月 10, 2010
作者:
S
Santiago Pastorino
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove unused method
上级
b961c6c1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
0 addition
and
62 deletion
+0
-62
activesupport/lib/active_support/core_ext/object/instance_variables.rb
.../lib/active_support/core_ext/object/instance_variables.rb
+0
-31
activesupport/test/core_ext/object_and_class_ext_test.rb
activesupport/test/core_ext/object_and_class_ext_test.rb
+0
-31
未找到文件。
activesupport/lib/active_support/core_ext/object/instance_variables.rb
浏览文件 @
c2083859
...
...
@@ -30,35 +30,4 @@ def instance_variable_names
else
alias_method
:instance_variable_names
,
:instance_variables
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
activesupport/test/core_ext/object_and_class_ext_test.rb
浏览文件 @
c2083859
...
...
@@ -82,37 +82,6 @@ def test_instance_variable_names
assert_equal
%w(@bar @baz)
,
@source
.
instance_variable_names
.
sort
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
object
=
Object
.
new
object
.
instance_variable_set
:@a
,
1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录