Version bump to 0.0.0
parent
0aa247a5d3
commit
d27e96eb27
|
@ -0,0 +1,20 @@
|
||||||
|
GEM
|
||||||
|
remote: http://rubygems.org/
|
||||||
|
specs:
|
||||||
|
git (1.2.5)
|
||||||
|
jeweler (1.6.4)
|
||||||
|
bundler (~> 1.0)
|
||||||
|
git (>= 1.2.5)
|
||||||
|
rake
|
||||||
|
rake (0.9.2.2)
|
||||||
|
rcov (0.9.11)
|
||||||
|
shoulda (2.11.3)
|
||||||
|
|
||||||
|
PLATFORMS
|
||||||
|
ruby
|
||||||
|
|
||||||
|
DEPENDENCIES
|
||||||
|
bundler (~> 1.0.0)
|
||||||
|
jeweler (~> 1.6.4)
|
||||||
|
rcov
|
||||||
|
shoulda
|
|
@ -0,0 +1 @@
|
||||||
|
Basic library to do math on ranges, i.e. (3..4) + 5 = (8..9) and so on.
|
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
# coding: utf-8
|
||||||
|
# Copyright muflax <mail@muflax.com>, 2011
|
||||||
|
# License: GNU GPL 3 <http://www.gnu.org/copyleft/gpl.html>
|
||||||
|
|
||||||
|
class Range
|
||||||
|
def +(other)
|
||||||
|
if other.is_a? Range
|
||||||
|
(self.begin + other.begin)..(self.end + other.end)
|
||||||
|
elsif other.is_a? Numeric
|
||||||
|
(self.begin + other)..(self.end + other)
|
||||||
|
else
|
||||||
|
raise NoMethodError
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def -(other)
|
||||||
|
if other.is_a? Range
|
||||||
|
(self.begin - other.begin)..(self.end - other.end)
|
||||||
|
elsif other.is_a? Numeric
|
||||||
|
(self.begin - other)..(self.end - other)
|
||||||
|
else
|
||||||
|
raise NoMethodError
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def *(other)
|
||||||
|
if other.is_a? Range
|
||||||
|
(self.begin * other.begin)..(self.end * other.end)
|
||||||
|
elsif other.is_a? Numeric
|
||||||
|
(self.begin * other)..(self.end * other)
|
||||||
|
else
|
||||||
|
raise NoMethodError
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def /(other)
|
||||||
|
if other.is_a? Range
|
||||||
|
(self.begin / other.begin.to_f)..(self.end / other.end.to_f)
|
||||||
|
elsif other.is_a? Numeric
|
||||||
|
(self.begin / other.to_f)..(self.end / other.to_f)
|
||||||
|
else
|
||||||
|
raise NoMethodError
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def average
|
||||||
|
(self.begin + self.end) / 2.0
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue