diff options
author | Rashmi Yadav <rays.rashmi@gmail.com> | 2013-07-24 13:38:15 +0200 |
---|---|---|
committer | Rashmi Yadav <rays.rashmi@gmail.com> | 2013-07-24 13:42:22 +0200 |
commit | 990e8f06f63ce31d7eb34931b2b290a32f12dd20 (patch) | |
tree | 3c86b13110105d06d9799a1b42c1dba9e2c352f7 /guides | |
parent | 7e665d2397c550a352503dc9966d576b5ef355e9 (diff) | |
download | rails-990e8f06f63ce31d7eb34931b2b290a32f12dd20.tar.gz rails-990e8f06f63ce31d7eb34931b2b290a32f12dd20.tar.bz2 rails-990e8f06f63ce31d7eb34931b2b290a32f12dd20.zip |
Removed doc of removed method diff [ci skip]
Diffstat (limited to 'guides')
-rw-r--r-- | guides/source/active_support_core_extensions.md | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index b3dca3df24..f39fae060e 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -2661,44 +2661,6 @@ hash[:b][:d] == [3, 4] # => true NOTE: Defined in `active_support/core_ext/object/deep_dup.rb`. -### Diffing - -The method `diff` returns a hash that represents a diff of the receiver and the argument with the following logic: - -* Pairs `key`, `value` that exist in both hashes do not belong to the diff hash. - -* If both hashes have `key`, but with different values, the pair in the receiver wins. - -* The rest is just merged. - -```ruby -{a: 1}.diff(a: 1) -# => {}, first rule - -{a: 1}.diff(a: 2) -# => {:a=>1}, second rule - -{a: 1}.diff(b: 2) -# => {:a=>1, :b=>2}, third rule - -{a: 1, b: 2, c: 3}.diff(b: 1, c: 3, d: 4) -# => {:a=>1, :b=>2, :d=>4}, all rules - -{}.diff({}) # => {} -{a: 1}.diff({}) # => {:a=>1} -{}.diff(a: 1) # => {:a=>1} -``` - -An important property of this diff hash is that you can retrieve the original hash by applying `diff` twice: - -```ruby -hash.diff(hash2).diff(hash2) == hash -``` - -Diffing hashes may be useful for error messages related to expected option hashes for example. - -NOTE: Defined in `active_support/core_ext/hash/diff.rb`. - ### Working with Keys #### `except` and `except!` |