On Wed, Feb 16, 2011 at 11:26 AM, Frederick Cheung <[email protected]> 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 Ugh. And it is not equivalent. Before you could have an infinite number of points in between, now you can't (and have it working :). For a simple example take ordering in pairs of integers (imagine 2D points in a matrix if you want) defined by (a, b) < (c, d) iff a < c or (a = c, and b < d) define (a, b).next to be (a, b+1). I wrote this off the top of my head, but if I am not mistaken we have now a countable number of pairs between (1, 0) and (2, 0). Namely, (1, 1), (1, 2), .... So, using pseudonotation, ((1, 0)..(2, 0)).include?((3, 0)) won't even finish in 1.9, while it did before. This is just an example to depict why they are not equivalents, it might be artificial, but I don't know perhaps there's some application out there assuming this behavior. Anyway, that's a good catch, validates_inclusion_of should be based on inequalities. -- 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.
