diff options
author | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-09-12 13:46:33 -0500 |
---|---|---|
committer | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-09-12 13:47:49 -0500 |
commit | f4e180578c673194f58d4ff5a4a656cc51b2249e (patch) | |
tree | c1004a8c06730d9cea9f5dd0e5837f95f7713258 /activesupport/lib/active_support/hash_with_indifferent_access.rb | |
parent | 961355a9f34a9cdb3001d8a4b69741408145ebb8 (diff) | |
download | rails-f4e180578c673194f58d4ff5a4a656cc51b2249e.tar.gz rails-f4e180578c673194f58d4ff5a4a656cc51b2249e.tar.bz2 rails-f4e180578c673194f58d4ff5a4a656cc51b2249e.zip |
update some AS code examples to 1.9 hash syntax [ci skip]
Diffstat (limited to 'activesupport/lib/active_support/hash_with_indifferent_access.rb')
-rw-r--r-- | activesupport/lib/active_support/hash_with_indifferent_access.rb | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 71713644a7..7698bfc6b7 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -17,7 +17,7 @@ module ActiveSupport # writing interface (calling <tt>[]=</tt>, <tt>merge</tt>, etc). This # mapping belongs to the public interface. For example, given # - # hash = ActiveSupport::HashWithIndifferentAccess.new(:a => 1) + # hash = ActiveSupport::HashWithIndifferentAccess.new(a: 1) # # you are guaranteed that the key is returned as a string: # @@ -25,7 +25,7 @@ module ActiveSupport # # Technically other types of keys are accepted: # - # hash = ActiveSupport::HashWithIndifferentAccess.new(:a => 1) + # hash = ActiveSupport::HashWithIndifferentAccess.new(a: 1) # hash[0] = 0 # hash # => {"a"=>1, 0=>0} # @@ -35,7 +35,7 @@ module ActiveSupport # # Note that core extensions define <tt>Hash#with_indifferent_access</tt>: # - # rgb = {:black => '#000000', :white => '#FFFFFF'}.with_indifferent_access + # rgb = { black: '#000000', white: '#FFFFFF' }.with_indifferent_access # # which may be handy. class HashWithIndifferentAccess < Hash @@ -86,9 +86,9 @@ module ActiveSupport # Assigns a new value to the hash: # # hash = ActiveSupport::HashWithIndifferentAccess.new - # hash[:key] = "value" + # hash[:key] = 'value' # - # This value can be later fetched using either +:key+ or +"key"+. + # This value can be later fetched using either +:key+ or +'key'+. def []=(key, value) regular_writer(convert_key(key), convert_value(value)) end @@ -98,10 +98,10 @@ module ActiveSupport # Updates the receiver in-place, merging in the hash passed as argument: # # hash_1 = ActiveSupport::HashWithIndifferentAccess.new - # hash_1[:key] = "value" + # hash_1[:key] = 'value' # # hash_2 = ActiveSupport::HashWithIndifferentAccess.new - # hash_2[:key] = "New Value!" + # hash_2[:key] = 'New Value!' # # hash_1.update(hash_2) # => {"key"=>"New Value!"} # @@ -120,7 +120,6 @@ module ActiveSupport # hash_1[:key] = 10 # hash_2['key'] = 12 # hash_1.update(hash_2) { |key, old, new| old + new } # => {"key"=>22} - # def update(other_hash) if other_hash.is_a? HashWithIndifferentAccess super(other_hash) @@ -140,10 +139,9 @@ module ActiveSupport # Checks the hash for a key matching the argument passed in: # # hash = ActiveSupport::HashWithIndifferentAccess.new - # hash["key"] = "value" + # hash['key'] = 'value' # hash.key?(:key) # => true - # hash.key?("key") # => true - # + # hash.key?('key') # => true def key?(key) super(convert_key(key)) end @@ -158,11 +156,10 @@ module ActiveSupport # counters = ActiveSupport::HashWithIndifferentAccess.new # counters[:foo] = 1 # - # counters.fetch("foo") # => 1 + # counters.fetch('foo') # => 1 # counters.fetch(:bar, 0) # => 0 # counters.fetch(:bar) {|key| 0} # => 0 # counters.fetch(:zoo) # => KeyError: key not found: "zoo" - # def fetch(key, *extras) super(convert_key(key), *extras) end @@ -170,10 +167,9 @@ module ActiveSupport # Returns an array of the values at the specified indices: # # hash = ActiveSupport::HashWithIndifferentAccess.new - # hash[:a] = "x" - # hash[:b] = "y" - # hash.values_at("a", "b") # => ["x", "y"] - # + # hash[:a] = 'x' + # hash[:b] = 'y' + # hash.values_at('a', 'b') # => ["x", "y"] def values_at(*indices) indices.collect {|key| self[convert_key(key)]} end @@ -197,8 +193,7 @@ module ActiveSupport # # hash = ActiveSupport::HashWithIndifferentAccess.new # hash['a'] = nil - # hash.reverse_merge(:a => 0, :b => 1) # => {"a"=>nil, "b"=>1} - # + # hash.reverse_merge(a: 0, b: 1) # => {"a"=>nil, "b"=>1} def reverse_merge(other_hash) super(self.class.new_from_hash_copying_default(other_hash)) end |