-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphrase.rb
More file actions
executable file
·41 lines (35 loc) · 783 Bytes
/
Copy pathphrase.rb
File metadata and controls
executable file
·41 lines (35 loc) · 783 Bytes
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
class Phrase
def initialize
@letters = []
selection.each {|l| @letters << l.gsub(/[^a-zA-Z ]/, "")}
end
def selection
seed = phrases.length # Get the number of phrases
phrases[rand(seed)].split("").map {|x| x.upcase} # And use that for a random index
end
def letters
@letters
end
def show
@letters.to_s
end
# Return the number of letters in the phrase
def letter_count(spaces = true)
if spaces
@letters.length
elsif !!spaces
@letters.to_s.gsub(/[^a-zA-Z]/,"").length
end
end
# Returns true if the letter exists
def letter?(guess)
@letters.each {|l| return true if l == guess}
return false
end
def phrases
lines = []
file = File.open('phrases.dat', 'r').each {|line| lines << line.chomp }
file.close
return lines
end
end