Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
72f9fec6
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,发现更多精彩内容 >>
提交
72f9fec6
编写于
6月 13, 2010
作者:
X
Xavier Noria
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
hash merging with a block ignores non-existing keys altogether
上级
9183eaeb
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
17 addition
and
18 deletion
+17
-18
activesupport/lib/active_support/ordered_hash.rb
activesupport/lib/active_support/ordered_hash.rb
+1
-1
activesupport/test/ordered_hash_test.rb
activesupport/test/ordered_hash_test.rb
+16
-17
未找到文件。
activesupport/lib/active_support/ordered_hash.rb
浏览文件 @
72f9fec6
...
@@ -131,7 +131,7 @@ def shift
...
@@ -131,7 +131,7 @@ def shift
def
merge!
(
other_hash
)
def
merge!
(
other_hash
)
if
block_given?
if
block_given?
other_hash
.
each
{
|
k
,
v
|
self
[
k
]
=
yield
(
k
,
self
[
k
],
v
)
}
other_hash
.
each
{
|
k
,
v
|
self
[
k
]
=
yield
(
k
,
self
[
k
],
v
)
if
key?
k
}
else
else
other_hash
.
each
{
|
k
,
v
|
self
[
k
]
=
v
}
other_hash
.
each
{
|
k
,
v
|
self
[
k
]
=
v
}
end
end
...
...
activesupport/test/ordered_hash_test.rb
浏览文件 @
72f9fec6
...
@@ -144,28 +144,27 @@ def test_merge
...
@@ -144,28 +144,27 @@ def test_merge
end
end
def
test_merge_with_block
def
test_merge_with_block
other_
hash
=
ActiveSupport
::
OrderedHash
.
new
hash
=
ActiveSupport
::
OrderedHash
.
new
other_hash
[
'white'
]
=
'ff'
hash
[
:a
]
=
0
other_hash
[
'black'
]
=
'00'
hash
[
:b
]
=
0
merged
=
@ordered_hash
.
merge
(
other_hash
)
do
|
key
,
old_value
,
new_value
|
merged
=
hash
.
merge
(
:b
=>
1
,
:c
=>
2
)
do
|
key
,
old_value
,
new_value
|
new_value
*
3
new_value
+
1
end
end
assert_equal
'ffffff'
,
merged
[
'white'
]
assert_equal
0
,
merged
[
:a
]
assert_equal
'000000'
,
merged
[
'black'
]
assert_equal
2
,
merged
[
:b
]
assert
!
merged
.
key?
(
:c
)
assert_nil
@ordered_hash
[
'white'
]
assert_nil
@ordered_hash
[
'black'
]
end
end
def
test_merge_bang_with_block
def
test_merge_bang_with_block
other_hash
=
ActiveSupport
::
OrderedHash
.
new
hash
=
ActiveSupport
::
OrderedHash
.
new
other_hash
[
'white'
]
=
'ff'
hash
[
:a
]
=
0
other_hash
[
'black'
]
=
'00'
hash
[
:b
]
=
0
@ordered_hash
.
merge!
(
other_hash
)
do
|
key
,
old_value
,
new_value
|
hash
.
merge!
(
:a
=>
1
,
:c
=>
2
)
do
|
key
,
old_value
,
new_value
|
new_value
*
3
new_value
+
3
end
end
assert_equal
'ffffff'
,
@ordered_hash
[
'white'
]
assert_equal
4
,
hash
[
:a
]
assert_equal
'000000'
,
@ordered_hash
[
'black'
]
assert_equal
0
,
hash
[
:b
]
assert
!
hash
.
key?
(
:c
)
end
end
def
test_shift
def
test_shift
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录