[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Range does not take an Range object.

Tomoyuki Kosimizu

11/25/2003 6:47:00 PM

3 Answers

Dan Doel

11/25/2003 9:56:00 PM

0

class Range
alias_method :old_include?, :include?

def include?(obj)
if obj.is_a? Range
old_include? obj.first and
old_include? obj.last
else
old_include? obj
end
end

def intersect?(aRange)
aRange.each do |i|
return true if include? i
end

false
end
end

p (1..4).include? 2..3

p (1...4).include? 1..4

p (1..6).intersect? 4..8

p (1...6).intersect? 6..8


Dan Doel

11/25/2003 10:23:00 PM

0

Oops, that's slightly broken. Here's a fix.

class Range
alias_method :old_include?, :include?

def include?(obj)
if obj.is_a? Range
old_include? obj.first and
old_include? obj.exclude_end? ? obj.last-1 : obj.last
else
old_include? obj
end
end

def intersect?(aRange)
aRange.each do |i|
return true if include? i
end

false
end
end



Tomoyuki Kosimizu

11/27/2003 12:42:00 AM

0