Permalink
Browse files

range works

  • Loading branch information...
1 parent 588f49b commit 65151c2413f5cf12c6f49042cfe1312208074f70 @kristianmandrup committed Sep 25, 2012
Showing with 21 additions and 4 deletions.
  1. +1 −0 .rvmrc
  2. +1 −1 .travis.yml
  3. +2 −0 README.textile
  4. +16 −2 lib/sugar-high/range.rb
  5. +1 −1 lib/sugar-high/version.rb
View
@@ -0,0 +1 @@
+rvm use 1.9.2@sugar-high --create
View
@@ -1,6 +1,6 @@
language: ruby
rvm:
- - 1.8.7
+ - 1.9.2
- 1.9.3
script: "rake"
gemfile:
View
@@ -16,6 +16,8 @@ h2. Update Aug 21, 2011
Extracted *file_mutate* and *sweetloader* gems.
+Only tested for Ruby 1.9.2 and 1.9.3. Using *Travis CI*.
+
h2. Sugar packs
* alias
@@ -1,12 +1,26 @@
class Range
+ def intersection(other)
+ raise ArgumentError, 'value must be a Range' unless other.kind_of?(Range)
+
+ min, max = first, exclude_end? ? max : last
+ other_min, other_max = other.first, other.exclude_end? ? other.max : other.last
+
+ new_min = self === other_min ? other_min : other === min ? min : nil
+ new_max = self === other_max ? other_max : other === max ? max : nil
+
+ new_min && new_max ? new_min..new_max : nil
+ end
+
def intersect(other)
raise ArgumentError, 'value must be a Range' unless other.kind_of?(Range)
new_min = self.cover?(other.min) ? other.min : other.cover?(min) ? min : nil
new_max = self.cover?(other.max) ? other.max : other.cover?(max) ? max : nil
new_min && new_max ? new_min..new_max : nil
+
+ rescue # if above doesn't work for ruby version
+ intersection(other)
end
- alias_method :intersection, :intersect
- alias_method :&, :intersection
+ alias_method :&, :intersect
end
@@ -1,3 +1,3 @@
module SugarHigh
- VERSION = '0.7.1'
+ VERSION = '0.7.2'
end

0 comments on commit 65151c2

Please sign in to comment.