RubyRanges 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +10 -0
- data/lib/ruby_ranges/range.rb +8 -4
- data/lib/ruby_ranges/version.rb +1 -1
- data/test/ruby_ranges_test.rb +8 -20
- metadata +4 -4
data/Rakefile
CHANGED
data/lib/ruby_ranges/range.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
class Range
|
2
|
+
alias :old_include? :include?
|
3
|
+
end
|
4
|
+
|
1
5
|
module RubyRanges
|
2
6
|
module Range
|
3
|
-
|
4
7
|
def self.included(base)
|
5
8
|
base.send(:define_method, :include?) do |object|
|
6
|
-
object.is_a?(Range) ?
|
9
|
+
object.is_a?(Range) ?
|
10
|
+
include_range?(object) : old_include?(object)
|
7
11
|
end
|
8
12
|
end
|
9
13
|
|
@@ -42,7 +46,7 @@ module RubyRanges
|
|
42
46
|
when RubyRanges::DownwardIncluded.to_value # add downward inclusive range
|
43
47
|
range.begin..self.end
|
44
48
|
else # mutually exclusive
|
45
|
-
Array.new(self, range)
|
49
|
+
RubyRanges::Array.new(self, range)
|
46
50
|
end
|
47
51
|
end
|
48
52
|
|
@@ -51,7 +55,7 @@ module RubyRanges
|
|
51
55
|
when NilClass # self removed by larger range
|
52
56
|
nil
|
53
57
|
when TrueClass # self split by wholly inclusive range
|
54
|
-
Array.new(self.begin..range.begin, range.end..self.end)
|
58
|
+
RubyRanges::Array.new(self.begin..range.begin, range.end..self.end)
|
55
59
|
when 1 # self shortened by upload inclusive range
|
56
60
|
self.begin..range.begin
|
57
61
|
when -1 # self shortened by downward inclusive range
|
data/lib/ruby_ranges/version.rb
CHANGED
data/test/ruby_ranges_test.rb
CHANGED
@@ -5,6 +5,14 @@ class RubyRanges::RangeTest < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
include RubyRanges
|
7
7
|
|
8
|
+
def test_include_integer
|
9
|
+
assert (1..9).include?(3)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_include_real_number
|
13
|
+
assert (1..9).include?(3.5)
|
14
|
+
end
|
15
|
+
|
8
16
|
def test_include_partial_downward_range
|
9
17
|
assert_equal -1, (1..9).include?(-1..3).to_value
|
10
18
|
assert_equal RubyRanges::DownwardIncluded, (1..9).include?(-1..3)
|
@@ -52,10 +60,6 @@ class RubyRanges::RangeTest < Test::Unit::TestCase
|
|
52
60
|
assert_equal RubyRanges::Array.new((1..4), (8..9)), output
|
53
61
|
end
|
54
62
|
|
55
|
-
def test_adding_ruby_ranges_array
|
56
|
-
pending
|
57
|
-
end
|
58
|
-
|
59
63
|
def test_subtracting_wholly_included_range
|
60
64
|
output = (1..9) - (5..7)
|
61
65
|
assert_equal RubyRanges::Array.new(1..5, 7..9), output
|
@@ -80,20 +84,4 @@ class RubyRanges::RangeTest < Test::Unit::TestCase
|
|
80
84
|
assert_equal 1..9, output
|
81
85
|
end
|
82
86
|
|
83
|
-
def test_subtracting_wholly_inclusive_ruby_ranges_array
|
84
|
-
pending
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_subtracting_mutually_exclusive_ruby_ranges_array
|
88
|
-
pending
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_subtracting_downward_exclusive_ruby_ranges_array
|
92
|
-
pending
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_subtracting_upward_exclusive_ruby_ranges_array
|
96
|
-
pending
|
97
|
-
end
|
98
|
-
|
99
87
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: RubyRanges
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chris Winslett
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06
|
18
|
+
date: 2011-07-06 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|