From: Giuseppe Bilotta Date: Mon, 9 Apr 2007 21:17:05 +0000 (+0000) Subject: extends: pick_one and rand methods for Range X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=b455c0242fcdcbe2a4f51f61afd315757963da02;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git extends: pick_one and rand methods for Range --- 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