Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
bf8b9925
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,发现更多精彩内容 >>
提交
bf8b9925
编写于
11月 11, 2013
作者:
K
KD
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
documentation updated for Hashes [ci skip]
上级
4aadd160
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
18 addition
and
14 deletion
+18
-14
activesupport/lib/active_support/core_ext/hash/conversions.rb
...vesupport/lib/active_support/core_ext/hash/conversions.rb
+6
-3
activesupport/lib/active_support/core_ext/hash/deep_merge.rb
activesupport/lib/active_support/core_ext/hash/deep_merge.rb
+5
-5
activesupport/lib/active_support/core_ext/hash/indifferent_access.rb
...rt/lib/active_support/core_ext/hash/indifferent_access.rb
+1
-0
activesupport/lib/active_support/core_ext/hash/keys.rb
activesupport/lib/active_support/core_ext/hash/keys.rb
+6
-6
未找到文件。
activesupport/lib/active_support/core_ext/hash/conversions.rb
浏览文件 @
bf8b9925
...
...
@@ -10,7 +10,7 @@
class
Hash
# Returns a string containing an XML representation of its receiver:
#
# {
'foo' => 1, 'bar' => 2
}.to_xml
# {
foo: 1, bar: 2
}.to_xml
# # =>
# # <?xml version="1.0" encoding="UTF-8"?>
# # <hash>
...
...
@@ -43,7 +43,10 @@ class Hash
# end
#
# { foo: Foo.new }.to_xml(skip_instruct: true)
# # => "<hash><bar>fooing!</bar></hash>"
# # =>
# # <hash>
# # <bar>fooing!</bar>
# # </hash>
#
# * Otherwise, a node with +key+ as tag is created with a string representation of
# +value+ as text node. If +value+ is +nil+ an attribute "nil" set to "true" is added.
...
...
@@ -201,7 +204,7 @@ def become_array?(value)
end
def
become_empty_string?
(
value
)
# {
"string" => true
}
# {
"string" => true
}
# No tests fail when the second term is removed.
value
[
'type'
]
==
'string'
&&
value
[
'nil'
]
!=
'true'
end
...
...
activesupport/lib/active_support/core_ext/hash/deep_merge.rb
浏览文件 @
bf8b9925
class
Hash
# Returns a new hash with +self+ and +other_hash+ merged recursively.
#
# h1 = { x: { y: [4,
5,6] }, z: [7,8,
9] }
# h2 = { x: { y: [7,
8,
9] }, z: 'xyz' }
# h1 = { x: { y: [4,
5, 6] }, z: [7, 8,
9] }
# h2 = { x: { y: [7,
8,
9] }, z: 'xyz' }
#
# h1.deep_merge(h2) #
=> {x: {y: [7, 8, 9]}, z:
"xyz"}
# h2.deep_merge(h1) #
=> {x: {y: [4, 5, 6]}, z:
[7, 8, 9]}
# h1.deep_merge(h2) #
=> {:x=>{:y=>[7, 8, 9]}, :z=>
"xyz"}
# h2.deep_merge(h1) #
=> {:x=>{:y=>[4, 5, 6]}, :z=>
[7, 8, 9]}
# h1.deep_merge(h2) { |key, old, new| Array.wrap(old) + Array.wrap(new) }
# #=> {:x=>{:y=>[4, 5, 6, 7, 8, 9]}, :z=>[7, 8, 9, "xyz"]}
# #
=> {:x=>{:y=>[4, 5, 6, 7, 8, 9]}, :z=>[7, 8, 9, "xyz"]}
def
deep_merge
(
other_hash
,
&
block
)
dup
.
deep_merge!
(
other_hash
,
&
block
)
end
...
...
activesupport/lib/active_support/core_ext/hash/indifferent_access.rb
浏览文件 @
bf8b9925
...
...
@@ -18,5 +18,6 @@ def with_indifferent_access
#
# b = { b: 1 }
# { a: b }.with_indifferent_access['a'] # calls b.nested_under_indifferent_access
# # => {"b"=>32}
alias
nested_under_indifferent_access
with_indifferent_access
end
activesupport/lib/active_support/core_ext/hash/keys.rb
浏览文件 @
bf8b9925
...
...
@@ -4,7 +4,7 @@ class Hash
# hash = { name: 'Rob', age: '28' }
#
# hash.transform_keys{ |key| key.to_s.upcase }
# # => {
"NAME" => "Rob", "AGE" => "28"
}
# # => {
"NAME"=>"Rob", "AGE"=>"28"
}
def
transform_keys
result
=
{}
each_key
do
|
key
|
...
...
@@ -27,7 +27,7 @@ def transform_keys!
# hash = { name: 'Rob', age: '28' }
#
# hash.stringify_keys
# #
=> { "name" => "Rob", "age" => "28"
}
# #
=> {"name"=>"Rob", "age"=>"28"
}
def
stringify_keys
transform_keys
{
|
key
|
key
.
to_s
}
end
...
...
@@ -44,7 +44,7 @@ def stringify_keys!
# hash = { 'name' => 'Rob', 'age' => '28' }
#
# hash.symbolize_keys
# #
=> { name: "Rob", age: "28"
}
# #
=> {"name"=>"Rob", "age"=>"28"
}
def
symbolize_keys
transform_keys
{
|
key
|
key
.
to_sym
rescue
key
}
end
...
...
@@ -78,7 +78,7 @@ def assert_valid_keys(*valid_keys)
# hash = { person: { name: 'Rob', age: '28' } }
#
# hash.deep_transform_keys{ |key| key.to_s.upcase }
# # => {
"PERSON" => { "NAME" => "Rob", "AGE" => "28" }
}
# # => {
"PERSON"=>{"NAME"=>"Rob", "AGE"=>"28"}
}
def
deep_transform_keys
(
&
block
)
result
=
{}
each
do
|
key
,
value
|
...
...
@@ -105,7 +105,7 @@ def deep_transform_keys!(&block)
# hash = { person: { name: 'Rob', age: '28' } }
#
# hash.deep_stringify_keys
# # => {
"person" => { "name" => "Rob", "age" => "28" }
}
# # => {
"person"=>{"name"=>"Rob", "age"=>"28"}
}
def
deep_stringify_keys
deep_transform_keys
{
|
key
|
key
.
to_s
}
end
...
...
@@ -124,7 +124,7 @@ def deep_stringify_keys!
# hash = { 'person' => { 'name' => 'Rob', 'age' => '28' } }
#
# hash.deep_symbolize_keys
# # => {
person: { name: "Rob", age: "28" }
}
# # => {
:person=>{:name=>"Rob", :age=>"28"}
}
def
deep_symbolize_keys
deep_transform_keys
{
|
key
|
key
.
to_sym
rescue
key
}
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录