I am happy that there were at least three persons (included me) who
implemented Range#include? or intersect? incorrectly in the
world. And, interestingly, each person implement them in different
way.
It seems valuable that include? and intersect? are built-in.
greentea2fa2.so-net.ne.jp
class Range
alias_method
riginal_include?, :include?
def include?(other)
return original_include?(other) unless other.is_a?(Range)
return other.first >= first && other.last <= last
end
def intersect?(other)
return true if include?(other)
return include?(other.last) || include?(other.first) || other.include?(first) || other.include?(last)
end
end