Module | VestalVersions::Changes::HashMethods |
In: |
lib/vestal_versions/changes.rb
|
Instance methods included into Hash for dealing with manipulation of hashes in the specific format of ActiveRecord::Base#changes.
When called on a hash of changes and given a second hash of changes as an argument, append_changes will run the second hash on top of the first, updating the last element of each array value with its own, or creating its own key/value pair for missing keys. Resulting non-unique array values are removed.
first = {
"first_name" => ["Steve", "Stephen"], "age" => [25, 26]
} second = {
"first_name" => ["Stephen", "Steve"], "last_name" => ["Richert", "Jobs"], "age" => [26, 54]
} first.append_changes(second) # => {
"last_name" => ["Richert", "Jobs"], "age" => [25, 54]
}
Appends the existing hash of changes onto a given hash of changes. Relates to the append_changes method in the same way that Hash#reverse_merge relates to Hash#merge.