diff options
author | claudiob <claudiob@users.noreply.github.com> | 2018-07-05 06:08:31 -0700 |
---|---|---|
committer | claudiob <claudiob@users.noreply.github.com> | 2018-07-05 06:08:31 -0700 |
commit | 0cd36e2b22d9a6ef96364f97046d5fa47afcbc42 (patch) | |
tree | 826de12667343da1ec2b084f0de72a961915a050 /guides/source/5_2_release_notes.md | |
parent | ba38e13c8272f1d10cf2381d6e5d3021020c6f62 (diff) | |
download | rails-0cd36e2b22d9a6ef96364f97046d5fa47afcbc42.tar.gz rails-0cd36e2b22d9a6ef96364f97046d5fa47afcbc42.tar.bz2 rails-0cd36e2b22d9a6ef96364f97046d5fa47afcbc42.zip |
Shorter code: remove unnecessary condition
See https://github.com/rails/rails/commit/136fc65c9b8b66e1fb56f3a17f0d1fddff9b4bd0#r28897107
I _think_ that this method can now be rewritten from:
```ruby
def attribute_previous_change(attr)
previous_changes[attr] if attribute_previously_changed?(attr)
end
```
to:
```ruby
def attribute_previous_change(attr)
previous_changes[attr]
end
```
without losing performance.
---
Calling
```ruby
previous_changes[attr] if attribute_previously_changed?(attr)
```
is equivalent to calling
```ruby
previous_changes[attr] if previous_changes.include?(attr)
```
When this commit 136fc65c9b was made, Active Record had its own `previous_changes` method, added here below. However, that method has been recently removed from the codebase, so `previous_changes` is now only the method defined in Active Model as:
```ruby
def previous_changes
@previously_changed ||= ActiveSupport::HashWithIndifferentAccess.new
@previously_changed.merge(mutations_before_last_save.changes)
end
```
Since we are dealing with a memoized Hash, there is probably no need to check `if .include?(attr_name)` before trying to fetch `[attr]` for it.
Does that make sense? Did I miss anything? Thanks!
Diffstat (limited to 'guides/source/5_2_release_notes.md')
0 files changed, 0 insertions, 0 deletions