Need help with Ruby-related code; I'm tackling a sample practice problems and in the selected areas, I wanted to know how I can properly define and adjust the code to function. The ", :pending => true" parts have been removed/scratched out in order to allow the code to check if it works. (It's for checking purposes, ignore it) Topic: Case-sensitive and If else statement checks
Need help with Ruby-related code; I'm tackling a sample practice problems and in the selected areas, I wanted to know how I can properly define and adjust the code to function. The ", :pending => true" parts have been removed/scratched out in order to allow the code to check if it works. (It's for checking purposes, ignore it) Topic: Case-sensitive and If else statement checks
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%
Need help with Ruby-related code; I'm tackling a sample practice problems and in the selected areas, I wanted to know how I can properly define and adjust the code to function. The ", :pending => true" parts have been removed/scratched out in order to allow the code to check if it works. (It's for checking purposes, ignore it)
Topic: Case-sensitive and If else statement checks

Transcribed Image Text:47
end
48
end
49 -
context 'same letter repeatedly' do
before :each do
50 -
@game = HangpersonGame.new('garply')
guess_several_letters(@game, 'aq')
end
it 'does not change correct guess list', "pending - true do
@game.guess ('a')
expect (@game.guesses).to eq ('a')
end
it 'does not change wrong guess list'pending=>true do
@game.guess ('q')
expect (@game.wrong_guesses).to eq ('q')
end
51
52
54
55
56
57
58 -
59
60
61
it 'returns false', "pending
expect (@game.guess ('a')).to be false
expect (@game.guess ('q')).to be false
62 -
- true do
63
64
65
end
it 'is case insensitive'-ponding -\ truo do
expect (@game.guess ('A')).to be false
expect(@game.guess ('Q')).to be false
expect (@game.guesses).not_to include('A')
expect(@game.wrong_guesses).not_to include ('Q')
66 -
67
68
69
70
71
end
72
end
73 -
context 'invalid' do
HN3 4

Transcribed Image Text:l- class HangpersonGame
2
# add the necessary class methods, attributes, etc. here
# to make the tests in spec/hangperson_game_spec.rb pass.
3
# Get a word from remote "random word" service
7
8
# def initialize()
9
# end
10
11 -
def initialize (word)
12
@word = word
13
@guesses = ""
14
@wrong_guesses = ""
15 ,
end
16
17
def word
18
return @word
19
end
20
21
def guesses
22
return @guesses
23
end
24
25 ,
def wrong_guesses
26
return @wrong_guesses
27 -
end
28
def guess (letter)
if @word.include? (letter)
@guesses += letter
29 ,
30 -
31 -
32
return true
33
else
@wrong_guesses += letter
end
34
35
36
end
37
def word_with_guesses
partial_matches = ""
@word.each_char do |w|
partial_matches += "-"
end
38 -
39
40 -
41
42
43
return partial_matches
44
end
45
# You can test it by running $ bundle exec irb -I. -r app.rb
# And then in the irb: irb(main):001:0> HangpersonGame.get_random_word
=> "cooking"
def self.get_random_word
require 'uri'
require 'net/http'
uri = URI('http://randomword.saasbook.info/RandomWord')
Net::HTTP.new ( 'randomword.saasbook.info').start { |http|
return http. post (uri, "").body
}
46
47
48
#3
<-- some random word
49 ,
50
51
52
53 ,
54
55
56
end
57
58
end
59
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education