diff options
author | Xavier Noria <fxn@hashref.com> | 2008-05-07 20:32:02 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2008-05-07 20:32:02 +0200 |
commit | c434d206f15ec1df92070294bfa41931cd9b11bb (patch) | |
tree | d6989c8bd0c79664376b770868181939a9ce1f9d /activesupport | |
parent | d9db5012879f0fc2a2e5f73aa3c6caddd49e48be (diff) | |
download | rails-c434d206f15ec1df92070294bfa41931cd9b11bb.tar.gz rails-c434d206f15ec1df92070294bfa41931cd9b11bb.tar.bz2 rails-c434d206f15ec1df92070294bfa41931cd9b11bb.zip |
revised docs of hash with indiferent access
Includes addtional docs from http://rails.lighthouseapp.com/projects/8994/tickets/134
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/indifferent_access.rb | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb b/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb index 2213b09144..c96c5160b3 100644 --- a/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb +++ b/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb @@ -23,10 +23,7 @@ class HashWithIndifferentAccess < Hash alias_method :regular_writer, :[]= unless method_defined?(:regular_writer) alias_method :regular_update, :update unless method_defined?(:regular_update) - # - # Assigns a new value to the hash. - # - # Example: + # Assigns a new value to the hash: # # hash = HashWithIndifferentAccess.new # hash[:key] = "value" @@ -35,25 +32,15 @@ class HashWithIndifferentAccess < Hash regular_writer(convert_key(key), convert_value(value)) end + # Updates the instantized hash with values from the second: # - # Updates the instantized hash with values from the second. - # - # Example: - # - # >> hash_1 = HashWithIndifferentAccess.new - # => {} - # - # >> hash_1[:key] = "value" - # => "value" - # - # >> hash_2 = HashWithIndifferentAccess.new - # => {} + # hash_1 = HashWithIndifferentAccess.new + # hash_1[:key] = "value" # - # >> hash_2[:key] = "New Value!" - # => "New Value!" + # hash_2 = HashWithIndifferentAccess.new + # hash_2[:key] = "New Value!" # - # >> hash_1.update(hash_2) - # => {"key"=>"New Value!"} + # hash_1.update(hash_2) # => {"key"=>"New Value!"} # def update(other_hash) other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) } @@ -62,7 +49,13 @@ class HashWithIndifferentAccess < Hash alias_method :merge!, :update - # Checks the hash for a key matching the argument passed in + # Checks the hash for a key matching the argument passed in: + # + # hash = HashWithIndifferentAccess.new + # hash["key"] = "value" + # hash.key? :key # => true + # hash.key? "key" # => true + # def key?(key) super(convert_key(key)) end @@ -76,7 +69,13 @@ class HashWithIndifferentAccess < Hash super(convert_key(key), *extras) end - # Returns an array of the values at the specified indicies. + # Returns an array of the values at the specified indices: + # + # hash = HashWithIndifferentAccess.new + # 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 |