1
1
#!usr/bin/env ruby
2
2
3
- game_title = 'Ruby Blanks Game'
3
+ # Title of the game
4
+ puts '-' * 19
5
+ puts '| Ruby Blanks Game|'
6
+ puts '-' * 19
4
7
5
- # Wraps the game title with dashes.
6
- game_title = "| #{ game_title } |"
7
- game_title . length . times do
8
- print '-'
9
- end
10
-
11
- puts "\n #{ game_title } "
8
+ # Sets a value to look for blanks in sentences.
9
+ blanks = [ 'noun' , 'noun' , 'adjective' , 'verb' ]
12
10
13
- game_title . length . times do
14
- print '-'
11
+ # Prompts user to fill in the blanks, one by one.
12
+ answers = blanks . map do |blank |
13
+ indefinite_article = blank . start_with? ( 'a' ) ? 'an' : 'a'
14
+ print "Give me #{ indefinite_article } #{ blank } : "
15
+ response = gets . chomp
15
16
end
16
- puts
17
17
18
- # I went to ____ and found a ____, it looked like _____ so I _____ .
19
- # Next thing you know, the _____ was _____ like everyone else. It was ______ and ______.
18
+ # Fills the blanks in the sentence with captured answers .
19
+ text = "I went to visit a #{ answers [ 0 ] } and found a #{ answers [ 1 ] } , it looked #{ answers [ 2 ] } so I started to #{ answers [ 3 ] } ."
20
20
21
- blanks = [ 'noun' , 'noun' , 'adjective' , 'verb' ]
22
- responses = [ ]
23
- # blanks = ['noun', 'verb', 'adjective', 'adjective']
24
-
25
- for blank in blanks
26
- indefinite_article = blank . start_with? ( 'a' ) ? 'an' : 'a'
27
- print "Give me a #{ blank } : "
28
- responses << gets . chomp
29
- end
21
+ # Shows complete sentence to the user.
22
+ puts text
0 commit comments