summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/core/utils/extends.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/rbot/core/utils/extends.rb b/lib/rbot/core/utils/extends.rb
index 4b7e57f3..b812a676 100644
--- a/lib/rbot/core/utils/extends.rb
+++ b/lib/rbot/core/utils/extends.rb
@@ -27,6 +27,24 @@ class ::Array
end
end
+# Extensions for the Numeric classes
+#
+class ::Numeric
+
+ # This method forces a real number to be not more than a given positive
+ # number or not less than a given positive number, or between two any given
+ # numbers
+ #
+ def clip(left,right=0)
+ raise ArgumentError unless left.kind_of?(Numeric) and right.kind_of?(Numeric)
+ l = [left,right].min
+ u = [left,right].max
+ return l if self < l
+ return u if self > u
+ return self
+ end
+end
+
# Extensions to the String class
#
# TODO make ircify_html() accept an Hash of options, and make riphtml() just