Nice find. Yes, I think we should check that :cover? is defined then use it on 1.9.
Can you make the patch and create a ticket on Lighthouse? I'll review the patch and ask someone to get it in. Prem On 16 ?.?. 2554, at 17:26, Frederick Cheung wrote: > I found out today that Range#include? behaves differently on 1.9 than on 1.8 > ( http://rhnh.net/2009/08/03/range-include-in-ruby-1-9 ) > In order to deal with various edge cases, instead of just checking whether > range.first <= value <= range.last, in ruby 1.9 include? steps through all > the values in the range, checking for equality. > > This is of course a lot slower - in my case, checking a date for inclusion in > a 100 year Date range (via a validates_inclusion_of) went from instantaneous > to over 100ms. I think this sort of thing is probably pretty common in rails > apps and that the edge cases this change was designed to address are > extremely unlikely to crop up with validates_inclusion_of - people are almost > always going to be validating plain old strings, dates etc. > > The old include? logic is available as cover? in ruby 1.9. What should (if > anything) rails do? Options include > - change validates_inclusion_of to use cover? for ranges on ruby 1.9 > - add an option to validates_inclusion_of to use cover? instead of include > - add a new validation > > Personally, in the interest of squashing hidden gotchas when migrating to > 1.9, I'd be inclined to go for the first of the above options (and maybe let > people force the use of include? if they need it for one of these special > edge cases). > > Fred > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
