Skip to content

Commit 384d0e2

Browse files
committed
mruby-range-ext: implement Range#overlap? method
Which is implemented in CRuby recently.
1 parent 393aaad commit 384d0e2

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

mrbgems/mruby-range-ext/mrblib/range.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,12 @@ def min(&block)
9696
# delegate to Enumerable
9797
super()
9898
end
99+
100+
# Compare two ranges and see if they overlap each other
101+
# (1..5).overlap?(4..6) # => true
102+
# (1..5).overlap?(7..9) # => false
103+
def overlap?(other)
104+
raise TypeError, "argument must be a range" unless other.kind_of?(Range)
105+
other.begin == self.begin || self.cover?(other.begin) || other.cover?(self.begin)
106+
end
99107
end

0 commit comments

Comments
 (0)