aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/hash_with_indifferent_access.rb
Commit message (Collapse)AuthorAgeFilesLines
* Deprecate `HWIDA.new_from_hash_copying_default`Sean Griffin2015-10-291-0/+5
| | | | This method was already niche, and is now redundant with `.new`
* Merge pull request #16357 from gchan/hwia-respects-to-hash-defaultSean Griffin2015-10-291-7/+7
|\ | | | | | | | | `HashWithIndifferentAccess.new` respects the default value or proc on objects that respond to `#to_hash`
| * `HashWithIndifferentAccess.new` respects the default value or proc on ↵Gordon Chan2014-07-311-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | objects that respond to `#to_hash`. Builds on the work of #12550 where `.new` will convert the object (that respond to `#to_hash`) to a hash and add that hash's keys and values to itself. This change will also make `.new` respect the default value or proc of objects that respond to `#to_hash`. In other words, this `.new` behaves exactly like `.new_from_hash_copying_default`. `.new_from_hash_copying_default` now simply invokes `.new` and any references to `.new_from_hash_copying_default` are replaced with `.new`. Added tests confirm behavior.
* | [ci skip] Fix rdoc markupakihiro172015-08-121-1/+1
| |
* | ActiveSupport::HashWithIndifferentAccess select and reject should return ↵Bernard Potocki2015-07-171-0/+2
| | | | | | | | enumerator if called without block
* | active_support/indifferent_hash: dont raise on to_hash when default_proc raisesSimon Eskildsen2015-07-101-1/+3
| |
* | active_support/indifferent_hash: fix cloning default_proc on dupSimon Eskildsen2015-07-101-1/+9
| |
* | Revert "Improve the performance of HWIDA `select` and `reject`"Sean Griffin2015-02-061-4/+4
| | | | | | | | This reverts commit 9c47b874d112414df7f80f9ed852adb48ba6d268.
* | Improve the performance of HWIDA `select` and `reject`Sean Griffin2015-02-061-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These are (potentially, depending on input) called in several places in both the router, and Active Record. The code also becomes much cleaner. This results in ~33% performance gain in both methods. Calculating ------------------------------------- before 15.696k i/100ms after 19.865k i/100ms ------------------------------------------------- before 303.064k (± 2.6%) i/s - 1.523M after 446.734k (± 2.4%) i/s - 2.245M On Ruby 2.2, a warning will be emitted about states not being copied, because we're calling `super` from a subclass. We can safely ignore it, however, since we're converting the result back into a HWIDA
* | Fix assignment for frozen value in HWIAAditya Kapoor2015-01-171-1/+1
| |
* | Add necessary 'require reverse_merge' to HAWI.rbclaudiob2014-10-171-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hashes with indifferent access should support `reverse_merge` out-of-the-box but they don't; for instance the following code fails: ```ruby require 'active_support' require 'active_support/hash_with_indifferent_access' hash = HashWithIndifferentAccess.new key: :old_value hash.reverse_merge key: :new_value ``` This PR fixes the case above by simply requiring `active_support/core_ext/hash/reverse_merge` in `hash_with_indifferent_access.rb` and adding a test that confirms the fix. --- Here are more details about the bugfix. Currently, `reverse_merge` is [defined in HashWithIndifferentAccess](https://github.com/rails/rails/blob/4e8ea13ba1a0870905a46fac5f232d9f41eef8a4/activesupport/lib/active_support/hash_with_indifferent_access.rb#L208) by invoking `super`, that is by invoking `Hash#reverse_merge`: ```ruby def reverse_merge(other_hash) super(self.class.new_from_hash_copying_default(other_hash)) end ``` However, Ruby's `Hash` does not have the `reverse_merge` by default: it must be added by ActiveSupport, and that requires the following line of code to be present: ```ruby require 'active_support/core_ext/hash/reverse_merge' ```
* | Avoid creating an extra hashCarlos Antonio da Silva2014-07-311-2/+2
|/
* Removed unnecessary call to 'convert_key' in 'HashWithIndifferentAccess#to_hash'Gordon Chan2014-07-311-2/+2
| | | | All the keys are already Strings by virtue of being a HashWithIndifferentAccess.
* Make HWIA copy the default proc too.Arthur Neves2014-07-241-0/+1
| | | | [fixes #16279]
* Fix bug that make HashWithIndifferentAccess work differently of HashRafael Mendonça França2014-06-091-1/+1
| | | | | Before HashWithIndifferentAccess were doing deep_dup of the inner hashes when Hash doesn't do. Now both are behaving in the same way.
* [ci skip] Correct documentation of HashWithIndifferentAccess#dupAkshay Vishnoi2014-05-311-2/+2
|
* HashWithIndifferentAccess#dup doc [ci skip]James Blanding2014-05-301-1/+8
| | | | | The phrase "exact copy" in the existing docmentation is somewhat misleading.
* HashWithIndifferentAccess better respects #to_hashPeter Jaros2014-03-281-3/+4
| | | | | | In particular, `.new`, `#update`, `#merge`, `#replace` all accept objects which respond to `#to_hash`, even if those objects are not Hashes directly.
* Consistence in the block styleRafael Mendonça França2014-01-171-4/+4
|
* Remove warnings on Ruby 2.1Rafael Mendonça França2014-01-171-1/+5
|
* Change syntax format for example returned valuesPrem Sichanugrist2013-11-111-1/+1
| | | | | | | | | According to our guideline, we leave 1 space between `#` and `=>`, so we want `# =>` instead of `#=>`. Thanks to @fxn for the suggestion. [ci skip]
* Make HashWithIndifferentAccess#select always return the hash.Marc Schütz2013-07-061-1/+1
| | | | | Hash#select! returns nil if the hash didn't change and thus behaves differently from select, so it's return value can't be used as result for the latter.
* Merge pull request #10627 from vipulnsward/destructive_symbolizeCarlos Antonio da Silva2013-06-251-1/+1
|\ | | | | Change to destructive `deep_symbolize_keys` to avoid a new hash creation.
| * change to destructive `deep_symbolize_keys` after ↵Vipul A M2013-05-151-1/+1
| | | | | | | | https://github.com/rails/rails/commit/df24b8790f22384a068fece7042f04ffd2fcb33e which allows to do so. This helps to avoid extra hash object creation, by symbolizing inplace
* | Merge pull request #10740 from mrsimo/hash-with-indifferent-access-selectRafael Mendonça França2013-06-141-0/+4
|\ \ | | | | | | HashWithIndifferentAccess#select working as intended
| * | HashWithIndifferentAccess#select working as intendedAlbert Llop2013-05-231-0/+4
| | | | | | | | | | | | | | | | | | Before this commit, #reject returned a HashWithIndifferentAccess, whereas #select returned a Hash. Now #select also returns a HashWithIndifferentAccess.
* | | Prevent side effects in `Hash#with_indifferent_access`.Yves Senn2013-05-291-6/+12
|/ /
* / Fix HWIA#to_hash behavior with array of hashes.kennyj2013-05-161-2/+2
|/
* Merge pull request #10266 from vipulnsward/fix_HIA_to_hashRafael Mendonça França2013-05-141-3/+7
|\ | | | | fix HashWithIndifferentAccess#to_hash behaviour
| * fix HashWithIndifferentAccess#to_hash behaviourVipul A M2013-04-191-3/+7
| |
* | symbolize_keys => symbolize_keys! on new hash;Vipul A M2013-04-191-1/+1
|/ | | | "There're" => There are for better readability
* change merge to merge!Vipul A M2013-03-291-1/+1
|
* Implement replace method so key? works correctly.David Graham2012-10-261-0/+8
|
* update AS docs [ci skip]Francesco Rodriguez2012-09-171-4/+5
|
* update some AS code examples to 1.9 hash syntax [ci skip]Francesco Rodriguez2012-09-121-19/+14
|
* Extend HashWithIndifferentAccess#update to take an optional blockLeo Cassarani2012-09-051-6/+21
| | | | | | | | | | | | | When a block is passed into the method, it will be invoked for each duplicated key, with the key in question and the two values as arguments. The value for the duplicated key in the receiver will be set to the return value of the block. This behaviour matches Ruby's long-standing implementation of Hash#update and is intended to provide a more consistent interface. HashWithIndifferentAccess#merge is also affected by the change, as it uses #update internally.
* +"foo"+ doesn't generate code tag [ci skip]Rafael Mendonça França2012-07-211-1/+1
|
* Lets be consistent with whitespaces at documentationRafael Mendonça França2012-07-211-13/+13
|
* makes a pass over the API of ActiveSupport::HashWithIndifferentAccessXavier Noria2012-07-211-22/+70
|
* Hash#fetch(fetch) is not the same as doing hash[key]Xavier Noria2012-07-211-1/+11
|
* Use map! instead of replace + mapCarlos Antonio da Silva2012-06-181-1/+1
|
* Fix lookup on HashWithIndifferentAccess for array values.Chris Zetter2012-06-181-1/+2
|
* Adding deep versions of stringify_keys and symbolize_keys (plain and bang) ↵Lucas Húngaro2012-05-231-0/+4
| | | | for nested hashes
* fix HashWithIndifferentAccess.[] methodSergey Nartimov2012-03-231-0/+4
|
* search private and protected methods for convert_keyAaron Patterson2012-03-201-1/+1
|
* Clean up module docs [ci skip]Vijay Dev2012-03-071-4/+3
| | | | Removed some useless docstrings and no-doc'ed some.
* Overrode Hash#nested_under_indifferent_access in HashWithIndifferentAccessMiles Georgi2011-12-111-0/+4
| | | | to return self.
* docs formatting changesVijay Dev2011-09-011-1/+1
|
* document HashWithIndifferentAccess#extractable_options?Shawn Drost2011-07-071-0/+2
|
* Use dup to preserve previous behaviorDavid Lee2011-05-171-1/+1
|