From d27e96eb277492f336cec5178eadcd596a2fb155 Mon Sep 17 00:00:00 2001 From: muflax Date: Sun, 4 Dec 2011 14:18:40 +0100 Subject: [PATCH] Version bump to 0.0.0 --- Gemfile.lock | 20 +++++++++++++++++++ README | 1 + VERSION | 1 + lib/range_math.rb | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 Gemfile.lock create mode 100644 README create mode 100644 VERSION diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..549ba10 --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/README b/README new file mode 100644 index 0000000..c4a4935 --- /dev/null +++ b/README @@ -0,0 +1 @@ +Basic library to do math on ranges, i.e. (3..4) + 5 = (8..9) and so on. diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..bd52db8 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.0 \ No newline at end of file diff --git a/lib/range_math.rb b/lib/range_math.rb index e69de29..e797040 100644 --- a/lib/range_math.rb +++ b/lib/range_math.rb @@ -0,0 +1,50 @@ +#!/usr/bin/env ruby +# coding: utf-8 +# Copyright muflax , 2011 +# License: GNU GPL 3 + +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