Answered step by step
Verified Expert Solution
Question
1 Approved Answer
5 . 2 P M Static Type Checking in Ruby You can do these in Ed or the on - campus lab ( or your
P M Static Type Checking in Ruby
You can do these in Ed or the oncampus lab or your own computer For your own computer type: gem install steep then you can run steep.
To use steep in the standard way we need to create two folders.
lib For our code and its input files. In this case this means track.rb and track.txt the track data our code reads
sig For the rbs file in our case track.rbs which was produced by typeprof and describes the types in our track.rb program.
Take a look at these two folders in the Ed workshop and make sure you understand what is in each.
Steep will know where to find our program and its RBS type description by looking at a file called Steepfile.
our Steepfile is in the parent directory of lib and sig. Find the Steepfile in the Ed workspace and check its contents it should look as follows:
The Steepfile file tells steep where to find the code it is checking in lib and the type description in sig
Run the steep program in the parent directory in Ed as follows:
You should see the following output:
YOUR TASK: Fix the rbs file so that you produce the following output:
CODE track.rb :
class Track
attraccessor :name, :location
def initialize name location
@name name
@location location
end
end
# reads in a single track from the given file.
def readtrackafile
# complete this function
# you need to create a Track here.
name afile.gets
loc afile.gets
track Track.newname loc
return track
end
# Takes a single track and prints it to the terminal
def printtracktrack
putsTrack name: #trackname
putsTrack location: #tracklocation
end
# Open the file and read in the tracks then print them
def main
file File.newtracktxtr
track readtrackfile
file.close
printtracktrack
end
main if FILE $ # need this for the testing
CODE track.rbs
# TypeProf
# Classes
class Object
private
def readtrack: File afile nil
return rea
def printtrack: Track track nil
def main: nil
end
class Track
attraccessor name: String?
attraccessor location: String?
def initialize: String name, String? location void
end
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started