From 873ac28660b6cec15064a4d321e121f68e54ee06 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sun, 13 May 2012 12:22:43 -0500 Subject: adding examples to Hash#deep_merge method --- activesupport/lib/active_support/core_ext/hash/deep_merge.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/hash') diff --git a/activesupport/lib/active_support/core_ext/hash/deep_merge.rb b/activesupport/lib/active_support/core_ext/hash/deep_merge.rb index af771c86ff..2fa397bcd0 100644 --- a/activesupport/lib/active_support/core_ext/hash/deep_merge.rb +++ b/activesupport/lib/active_support/core_ext/hash/deep_merge.rb @@ -1,11 +1,16 @@ 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.deep_merge(h2) #=> {:x => {:y => [7, 8, 9]}, :z => "xyz"} + # h2.deep_merge(h1) #=> {:x => {:y => [4, 5, 6]}, :z => [7, 8, 9]} def deep_merge(other_hash) dup.deep_merge!(other_hash) end - # Returns a new hash with +self+ and +other_hash+ merged recursively. - # Modifies the receiver in place. + # Same as +deep_merge+, but modifies +self+ def deep_merge!(other_hash) other_hash.each_pair do |k,v| tv = self[k] -- cgit v1.2.3 From cb61f57a02488c92e1dc8cc8e8fa52ed5f249955 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sun, 13 May 2012 12:44:17 -0500 Subject: added example to Hash#stringify_keys --- activesupport/lib/active_support/core_ext/hash/keys.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext/hash') diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb index 230a84dabc..f72582571f 100644 --- a/activesupport/lib/active_support/core_ext/hash/keys.rb +++ b/activesupport/lib/active_support/core_ext/hash/keys.rb @@ -1,5 +1,8 @@ class Hash # Return a new hash with all keys converted to strings. + # + # { :name => 'Rob', :years => '28' }.stringify_keys + # #=> { "name" => "Rob", "years" => "28" } def stringify_keys result = {} keys.each do |key| @@ -8,7 +11,8 @@ class Hash result end - # Destructively convert all keys to strings. + # Destructively convert all keys to strings. Same as + # +stringify_keys+, but modifies +self+. def stringify_keys! keys.each do |key| self[key.to_s] = delete(key) -- cgit v1.2.3 From 817f9e64ee4e5b02efd9b4047c23340bf4b75586 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sun, 13 May 2012 12:45:25 -0500 Subject: unnecessary 'examples' noise in Hash#assert_valid_keys docs --- activesupport/lib/active_support/core_ext/hash/keys.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext/hash') diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb index f72582571f..057fff05e3 100644 --- a/activesupport/lib/active_support/core_ext/hash/keys.rb +++ b/activesupport/lib/active_support/core_ext/hash/keys.rb @@ -45,7 +45,6 @@ class Hash # Note that keys are NOT treated indifferently, meaning if you use strings for keys but assert symbols # as keys, this will fail. # - # ==== Examples # { :name => 'Rob', :years => '28' }.assert_valid_keys(:name, :age) # => raises "ArgumentError: Unknown key: years" # { :name => 'Rob', :age => '28' }.assert_valid_keys('name', 'age') # => raises "ArgumentError: Unknown key: name" # { :name => 'Rob', :age => '28' }.assert_valid_keys(:name, :age) # => passes, raises nothing -- cgit v1.2.3 From 92dbdb2340839f5d21b467eb68675f597fa3a588 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sun, 13 May 2012 12:49:15 -0500 Subject: added example to Hash#symbolize_keys --- activesupport/lib/active_support/core_ext/hash/keys.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/hash') diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb index 057fff05e3..81ee71d5fb 100644 --- a/activesupport/lib/active_support/core_ext/hash/keys.rb +++ b/activesupport/lib/active_support/core_ext/hash/keys.rb @@ -1,7 +1,7 @@ class Hash # Return a new hash with all keys converted to strings. # - # { :name => 'Rob', :years => '28' }.stringify_keys + # { name: 'Rob', years: '28' }.stringify_keys # #=> { "name" => "Rob", "years" => "28" } def stringify_keys result = {} @@ -22,6 +22,9 @@ class Hash # Return a new hash with all keys converted to symbols, as long as # they respond to +to_sym+. + # + # { 'name' => 'Rob', 'years' => '28' }.symbolize_keys + # #=> { :name => "Rob", :years => "28" } def symbolize_keys result = {} keys.each do |key| @@ -32,7 +35,7 @@ class Hash alias_method :to_options, :symbolize_keys # Destructively convert all keys to symbols, as long as they respond - # to +to_sym+. + # to +to_sym+. Same as +symbolize_keys+, but modifies self. def symbolize_keys! keys.each do |key| self[(key.to_sym rescue key)] = delete(key) -- cgit v1.2.3 From 16301cce760ad98c6dc07c53f67c990fd5d684b4 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sun, 13 May 2012 12:52:54 -0500 Subject: marking self in Hash#symbolize_keys! --- activesupport/lib/active_support/core_ext/hash/keys.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext/hash') diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb index 81ee71d5fb..e0aa352818 100644 --- a/activesupport/lib/active_support/core_ext/hash/keys.rb +++ b/activesupport/lib/active_support/core_ext/hash/keys.rb @@ -35,7 +35,7 @@ class Hash alias_method :to_options, :symbolize_keys # Destructively convert all keys to symbols, as long as they respond - # to +to_sym+. Same as +symbolize_keys+, but modifies self. + # to +to_sym+. Same as +symbolize_keys+, but modifies +self+. def symbolize_keys! keys.each do |key| self[(key.to_sym rescue key)] = delete(key) -- cgit v1.2.3 From bbd37753bf59a11a9e9b38a3ac7a94ec2906e188 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sun, 13 May 2012 19:47:27 -0500 Subject: Fixing Hash#stringify_keys docs --- activesupport/lib/active_support/core_ext/hash/keys.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext/hash') diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb index e0aa352818..be4d611ce7 100644 --- a/activesupport/lib/active_support/core_ext/hash/keys.rb +++ b/activesupport/lib/active_support/core_ext/hash/keys.rb @@ -1,7 +1,7 @@ class Hash # Return a new hash with all keys converted to strings. # - # { name: 'Rob', years: '28' }.stringify_keys + # { :name => 'Rob', :years => '28' }.stringify_keys # #=> { "name" => "Rob", "years" => "28" } def stringify_keys result = {} -- cgit v1.2.3 From fa03e37d31d7c69c90d41f0764c374318d8dced0 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sun, 13 May 2012 20:26:53 -0500 Subject: removing unnecessary 'examples' noise from activesupport --- activesupport/lib/active_support/core_ext/hash/diff.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/hash') diff --git a/activesupport/lib/active_support/core_ext/hash/diff.rb b/activesupport/lib/active_support/core_ext/hash/diff.rb index 855dcb38bc..831dee8ecb 100644 --- a/activesupport/lib/active_support/core_ext/hash/diff.rb +++ b/activesupport/lib/active_support/core_ext/hash/diff.rb @@ -1,8 +1,6 @@ class Hash # Returns a hash that represents the difference between two hashes. # - # Examples: - # # {1 => 2}.diff(1 => 2) # => {} # {1 => 2}.diff(1 => 3) # => {1 => 2} # {}.diff(1 => 2) # => {1 => 2} -- cgit v1.2.3 From 7cd88840939cac913899fa9a11281d78388672ad Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 15 May 2012 13:10:08 +0530 Subject: missing dot [ci skip] --- activesupport/lib/active_support/core_ext/hash/deep_merge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext/hash') diff --git a/activesupport/lib/active_support/core_ext/hash/deep_merge.rb b/activesupport/lib/active_support/core_ext/hash/deep_merge.rb index 2fa397bcd0..023bf68a87 100644 --- a/activesupport/lib/active_support/core_ext/hash/deep_merge.rb +++ b/activesupport/lib/active_support/core_ext/hash/deep_merge.rb @@ -10,7 +10,7 @@ class Hash dup.deep_merge!(other_hash) end - # Same as +deep_merge+, but modifies +self+ + # Same as +deep_merge+, but modifies +self+. def deep_merge!(other_hash) other_hash.each_pair do |k,v| tv = self[k] -- cgit v1.2.3