News for hackers. Stuff that matters.
Re:Reading the Ruby Source to Understand Rails Idiosyncrasies by danso on Saturday July 20, 2013 @05:01PM (#6076558)
Well, I learned about the cover? Method, so that's a big plus for a typical Saturday...but I'm confused as to why include? for ranges doesn't just act as an alias for cover?

I can't think of a Range that is not meant to be continuous...I would test out some cases right now if my computer weren't grinding away at a database insertion process...

edit: OK, tried it out....as I suspected, Ranges that consists of Strings will have different behavior:

    [16] pry(main)> ('aa'..'zz').include?('c')
    => false
    [17] pry(main)> ('aa'..'zz').cover?('c')
    => true
    [18] pry(main)> ('aa'..'zz').include?('cc')
    => true
    [19] pry(main)> ('aa'..'zz').cover?('cc')
    => true
    [20] pry(main)> ('aa'..'zz').cover?('cccccc')
Re:Reading the Ruby Source to Understand Rails Idiosyncrasies by norswap on Saturday July 20, 2013 @05:18PM (#6076615)
Ranges are always continuous, but `cover?` uses the comparison operators, while `include?` iterates over the items in the range in some cases. `include?` is practical in cases where you don't want to implement the comparison operators.

See https://news.ycombinator.com/item?id=6076608