Skip to content

Commit

Permalink
Add shuffle to String
Browse files Browse the repository at this point in the history
  • Loading branch information
samaaron committed Nov 19, 2014
1 parent a20447a commit 6d35d60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions app/server/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
#and other improvements
require 'osc-ruby'

class String
def shuffle
self.chars.to_a.shuffle.join
end
end

class Float
def times(&block)
self.to_i.times(&block)
Expand Down
7 changes: 5 additions & 2 deletions app/server/sonicpi/lib/sonicpi/spiderapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ def rand_i(max=2)


def shuffle(list)
return list.shuffle if list.respond_to? :shuffle
list.to_a.shuffle
end
doc name: :shuffle,
Expand All @@ -617,10 +618,12 @@ def shuffle(list)
args: [[:list, :array]],
opts: nil,
accepts_block: false,
doc: "Returns a new list with the same elements as the original but with their order shuffled.",
doc: "Returns a new list with the same elements as the original but with their order shuffled. Also works for strings",
examples: [
"
shuffle [1, 2, 3, 4] #=> Would return something like: [3, 4, 2, 1] "]
shuffle [1, 2, 3, 4] #=> Would return something like: [3, 4, 2, 1] ",
"
shuffle \"foobar\" #=> Would return something like: \"roobfa\"" ]

def choose(list)
list.to_a.choose
Expand Down

0 comments on commit 6d35d60

Please sign in to comment.