Skip to content

Commit bf8b992

Browse files
documentation updated for Hashes [ci skip]
1 parent 4aadd16 commit bf8b992

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

activesupport/lib/active_support/core_ext/hash/conversions.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class Hash
1111
# Returns a string containing an XML representation of its receiver:
1212
#
13-
# {'foo' => 1, 'bar' => 2}.to_xml
13+
# { foo: 1, bar: 2 }.to_xml
1414
# # =>
1515
# # <?xml version="1.0" encoding="UTF-8"?>
1616
# # <hash>
@@ -43,7 +43,10 @@ class Hash
4343
# end
4444
#
4545
# { foo: Foo.new }.to_xml(skip_instruct: true)
46-
# # => "<hash><bar>fooing!</bar></hash>"
46+
# # =>
47+
# # <hash>
48+
# # <bar>fooing!</bar>
49+
# # </hash>
4750
#
4851
# * Otherwise, a node with +key+ as tag is created with a string representation of
4952
# +value+ as text node. If +value+ is +nil+ an attribute "nil" set to "true" is added.
@@ -201,7 +204,7 @@ def become_array?(value)
201204
end
202205

203206
def become_empty_string?(value)
204-
# {"string" => true}
207+
# { "string" => true }
205208
# No tests fail when the second term is removed.
206209
value['type'] == 'string' && value['nil'] != 'true'
207210
end

activesupport/lib/active_support/core_ext/hash/deep_merge.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
class Hash
22
# Returns a new hash with +self+ and +other_hash+ merged recursively.
33
#
4-
# h1 = { x: { y: [4,5,6] }, z: [7,8,9] }
5-
# h2 = { x: { y: [7,8,9] }, z: 'xyz' }
4+
# h1 = { x: { y: [4, 5, 6] }, z: [7, 8, 9] }
5+
# h2 = { x: { y: [7, 8, 9] }, z: 'xyz' }
66
#
7-
# h1.deep_merge(h2) #=> {x: {y: [7, 8, 9]}, z: "xyz"}
8-
# h2.deep_merge(h1) #=> {x: {y: [4, 5, 6]}, z: [7, 8, 9]}
7+
# h1.deep_merge(h2) # => {:x=>{:y=>[7, 8, 9]}, :z=>"xyz"}
8+
# h2.deep_merge(h1) # => {:x=>{:y=>[4, 5, 6]}, :z=>[7, 8, 9]}
99
# h1.deep_merge(h2) { |key, old, new| Array.wrap(old) + Array.wrap(new) }
10-
# #=> {:x=>{:y=>[4, 5, 6, 7, 8, 9]}, :z=>[7, 8, 9, "xyz"]}
10+
# # => {:x=>{:y=>[4, 5, 6, 7, 8, 9]}, :z=>[7, 8, 9, "xyz"]}
1111
def deep_merge(other_hash, &block)
1212
dup.deep_merge!(other_hash, &block)
1313
end

activesupport/lib/active_support/core_ext/hash/indifferent_access.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ def with_indifferent_access
1818
#
1919
# b = { b: 1 }
2020
# { a: b }.with_indifferent_access['a'] # calls b.nested_under_indifferent_access
21+
# # => {"b"=>32}
2122
alias nested_under_indifferent_access with_indifferent_access
2223
end

activesupport/lib/active_support/core_ext/hash/keys.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Hash
44
# hash = { name: 'Rob', age: '28' }
55
#
66
# hash.transform_keys{ |key| key.to_s.upcase }
7-
# # => { "NAME" => "Rob", "AGE" => "28" }
7+
# # => {"NAME"=>"Rob", "AGE"=>"28"}
88
def transform_keys
99
result = {}
1010
each_key do |key|
@@ -27,7 +27,7 @@ def transform_keys!
2727
# hash = { name: 'Rob', age: '28' }
2828
#
2929
# hash.stringify_keys
30-
# #=> { "name" => "Rob", "age" => "28" }
30+
# # => {"name"=>"Rob", "age"=>"28"}
3131
def stringify_keys
3232
transform_keys{ |key| key.to_s }
3333
end
@@ -44,7 +44,7 @@ def stringify_keys!
4444
# hash = { 'name' => 'Rob', 'age' => '28' }
4545
#
4646
# hash.symbolize_keys
47-
# #=> { name: "Rob", age: "28" }
47+
# # => {"name"=>"Rob", "age"=>"28"}
4848
def symbolize_keys
4949
transform_keys{ |key| key.to_sym rescue key }
5050
end
@@ -78,7 +78,7 @@ def assert_valid_keys(*valid_keys)
7878
# hash = { person: { name: 'Rob', age: '28' } }
7979
#
8080
# hash.deep_transform_keys{ |key| key.to_s.upcase }
81-
# # => { "PERSON" => { "NAME" => "Rob", "AGE" => "28" } }
81+
# # => {"PERSON"=>{"NAME"=>"Rob", "AGE"=>"28"}}
8282
def deep_transform_keys(&block)
8383
result = {}
8484
each do |key, value|
@@ -105,7 +105,7 @@ def deep_transform_keys!(&block)
105105
# hash = { person: { name: 'Rob', age: '28' } }
106106
#
107107
# hash.deep_stringify_keys
108-
# # => { "person" => { "name" => "Rob", "age" => "28" } }
108+
# # => {"person"=>{"name"=>"Rob", "age"=>"28"}}
109109
def deep_stringify_keys
110110
deep_transform_keys{ |key| key.to_s }
111111
end
@@ -124,7 +124,7 @@ def deep_stringify_keys!
124124
# hash = { 'person' => { 'name' => 'Rob', 'age' => '28' } }
125125
#
126126
# hash.deep_symbolize_keys
127-
# # => { person: { name: "Rob", age: "28" } }
127+
# # => {:person=>{:name=>"Rob", :age=>"28"}}
128128
def deep_symbolize_keys
129129
deep_transform_keys{ |key| key.to_sym rescue key }
130130
end

0 commit comments

Comments
 (0)