summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-04-09 21:17:05 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-04-09 21:17:05 +0000
commitb455c0242fcdcbe2a4f51f61afd315757963da02 (patch)
tree27992bc0255c3c94c9f44db2c56d0ff277dd34f8
parent64affd3db4aaf1f65ea917f8851e6549311f3155 (diff)
extends: pick_one and rand methods for Range
-rw-r--r--lib/rbot/core/utils/extends.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/rbot/core/utils/extends.rb b/lib/rbot/core/utils/extends.rb
index a749f92a..bcea735b 100644
--- a/lib/rbot/core/utils/extends.rb
+++ b/lib/rbot/core/utils/extends.rb
@@ -27,6 +27,20 @@ class ::Array
end
end
+# Extensions to the Range class
+#
+class ::Range
+
+ # This method returns a random number between the lower and upper bound
+ #
+ def pick_one
+ len = self.last - self.first
+ len += 1 unless self.exclude_end?
+ self.first + Kernel::rand(len)
+ end
+ alias :rand :pick_one
+end
+
# Extensions for the Numeric classes
#
class ::Numeric