X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fcore%2Futils%2Fextends.rb;h=e62e2f21ea768ec846a7b607020ecaf6c4d9cf73;hb=d4ef91d819164d3a46dc2ce9e4a7ce14b6f5b043;hp=f3861745442035ebb60e926b61188ec3c0d5aec8;hpb=cfc6d31ac24b3c705eaa7302ced01d5f33135dc4;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/core/utils/extends.rb b/lib/rbot/core/utils/extends.rb index f3861745..e62e2f21 100644 --- a/lib/rbot/core/utils/extends.rb +++ b/lib/rbot/core/utils/extends.rb @@ -4,8 +4,6 @@ # :title: Standard classes extensions # # Author:: Giuseppe "Oblomov" Bilotta -# Copyright:: (C) 2006,2007 Giuseppe Bilotta -# License:: GPL v2 # # This file collects extensions to standard Ruby classes and to some core rbot # classes to be used by the various plugins @@ -109,6 +107,24 @@ class ::Array end self.delete_at(index) end + + # This method shuffles the items in the array + def shuffle! + base = self.dup + self.clear + while item = base.delete_one + self << item + end + self + end + + # This method returns a new array with the same items as + # the receiver, but shuffled + def shuffle + ret = self.dup + ret.shuffle! + end + end # Extensions to the Range class