Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

range works

  • Loading branch information...
commit 65151c2413f5cf12c6f49042cfe1312208074f70 1 parent 588f49b
Kristian Mandrup authored
1  .rvmrc
... ... @@ -0,0 +1 @@
  1 +rvm use 1.9.2@sugar-high --create
2  .travis.yml
... ... @@ -1,6 +1,6 @@
1 1 language: ruby
2 2 rvm:
3   - - 1.8.7
  3 + - 1.9.2
4 4 - 1.9.3
5 5 script: "rake"
6 6 gemfile:
2  README.textile
Source Rendered
@@ -16,6 +16,8 @@ h2. Update Aug 21, 2011
16 16
17 17 Extracted *file_mutate* and *sweetloader* gems.
18 18
  19 +Only tested for Ruby 1.9.2 and 1.9.3. Using *Travis CI*.
  20 +
19 21 h2. Sugar packs
20 22
21 23 * alias
18 lib/sugar-high/range.rb
... ... @@ -1,4 +1,16 @@
1 1 class Range
  2 + def intersection(other)
  3 + raise ArgumentError, 'value must be a Range' unless other.kind_of?(Range)
  4 +
  5 + min, max = first, exclude_end? ? max : last
  6 + other_min, other_max = other.first, other.exclude_end? ? other.max : other.last
  7 +
  8 + new_min = self === other_min ? other_min : other === min ? min : nil
  9 + new_max = self === other_max ? other_max : other === max ? max : nil
  10 +
  11 + new_min && new_max ? new_min..new_max : nil
  12 + end
  13 +
2 14 def intersect(other)
3 15 raise ArgumentError, 'value must be a Range' unless other.kind_of?(Range)
4 16
@@ -6,7 +18,9 @@ def intersect(other)
6 18 new_max = self.cover?(other.max) ? other.max : other.cover?(max) ? max : nil
7 19
8 20 new_min && new_max ? new_min..new_max : nil
  21 +
  22 + rescue # if above doesn't work for ruby version
  23 + intersection(other)
9 24 end
10   - alias_method :intersection, :intersect
11   - alias_method :&, :intersection
  25 + alias_method :&, :intersect
12 26 end
2  lib/sugar-high/version.rb
... ... @@ -1,3 +1,3 @@
1 1 module SugarHigh
2   - VERSION = '0.7.1'
  2 + VERSION = '0.7.2'
3 3 end

0 comments on commit 65151c2

Please sign in to comment.
Something went wrong with that request. Please try again.