In many cases I see this kind of condition: if status_id_changed? && status_id == Status::ACCEPTED So maybe it will be nice to introduce a new method like: if status_id_changed_to?(Status::ACCEPTED) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.
I use this kind of conditional around the place too. I''m -1 on adding more dynamic methods though. I''d sooner see something like `#changed?` extended: p = Person.new p.name = ''Nicholas'' p.changed? => true p.changed?(:name) => true p.changed?(:age) => false p.changed?(name: ''Nicholas'') => true p.changed?(name: ''Nick'') => false What do you think? On Tuesday, November 26, 2013 8:50:05 PM UTC+11, Yarin Go wrote:> > In many cases I see this kind of condition: > > if status_id_changed? && status_id == Status::ACCEPTED > > So maybe it will be nice to introduce a new method like: > > if status_id_changed_to?(Status::ACCEPTED) > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.
On 28-Nov-2013, at 7:26 am, Nicholas Firth-McCoy <nfm@nfm.id.au> wrote:> p.changed?(name: ''Nicholas'') => trueIf this is happening, it might be nice to test on both the old and the new value p.changed?(name: {“Nick” => “Nicholas”}) -- Tejas Dinkar http://www.nilenso.com Nilenso Software (formerly C42 Engineering) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.
I’ve created a pull request to make this happen.
https://github.com/rails/rails/pull/13131
model.name_changed?("Ringo")
model.name_changed?("John" => "Ringo")
On 02-Dec-2013, at 9:04 am, Tejas Dinkar <tejasdinkar@gmail.com>
wrote:> On 28-Nov-2013, at 7:26 am, Nicholas Firth-McCoy <nfm@nfm.id.au>
wrote:
>> p.changed?(name: ''Nicholas'') => true
>
>
> If this is happening, it might be nice to test on both the old and the new
value
>
> p.changed?(name: {“Nick” => “Nicholas”})
> --
> Tejas Dinkar
> http://www.nilenso.com
> Nilenso Software (formerly C42 Engineering)
--
Tejas Dinkar
http://www.nilenso.com
Nilenso Software (formerly C42 Engineering)
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.