-
Notifications
You must be signed in to change notification settings - Fork 0
/
shuffle_play.rb
61 lines (47 loc) · 890 Bytes
/
shuffle_play.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env ruby
# shuffle_play
class Array
=begin rdoc
Non-destructive; returns a copy of self, re-ordered randomly.
=end
def shuffle()
sort_by { rand }
end
=begin rdoc
Destructive; re-orders self randomly.
=end
def shuffle!()
replace(shuffle)
end
=begin rdoc
While we're here, we might as well offer a method
for pulling out a random member of the <b>Array</b>.
=end
def random_element()
shuffle[0]
end
end # Array
###
class ShufflePlayer
def initialize(files)
@files = files
end
=begin rdoc
Plays a shuffled version of self with the play_file method.
=end
def play()
@files.shuffle.each do |file|
play_file(file)
end
end
private
=begin rdoc
Uses ogg123, assumes presence and appropriateness.
=end
def play_file(file)
system("ogg123 #{file}")
end
end # ShufflePlayer
###
sp = ShufflePlayer.new(ARGV)
sp.play()