From: Robert Klemme Date: 2005-07-14T00:50:51+09:00 Subject: Re: NoMethodError in Range#include? Levin Alexander wrote: > Luke Worth wrote: > >>> $ ruby -e "puts(('a'..'z').include?(1))" >>> -e:1:in `include?': undefined method `>' for false:FalseClass >>> (NoMethodError) > >> I think this has something to do with the implementation of >> Range#include? (being that it returns rng.start <= val <= rng.end) > > But I think Range#include? should catch the Exception and return false > instead. > >> An easy way around it is to use ('a'..'z').entries.include?(1) >> instead > > That does not work when Range#start is a Float (and it builds an > additional Array) Also, there are several equally valid interpretations of Range#include?: - True, if the range while iterating yields the specific value (std definition from Enumerable) - True, if low <= x <= high - True, if low < x <= high .... So maybe Range#include? is not that useful after all... Or we should leave the std definition from Enumerable in place and introduce Range#contains? or Range#covers? to deal with the more range specific interpretations. Kind regards robert