Question: 5 . 2 P M Static Type Checking in Ruby You can do these in Ed or the on - campus lab ( or your

5.2P M Static Type Checking in Ruby
You can do these in Ed or the on-campus 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 1 track.rb :
class Track
attr_accessor :name, :location
def initialize (name, location)
@name = name
@location = location
end
end
# reads in a single track from the given file.
def read_track(a_file)
# complete this function
# you need to create a Track here.
name = a_file.gets
loc = a_file.gets
track = Track.new(name, loc)
return track
end
# Takes a single track and prints it to the terminal
def print_track(track)
puts("Track name: #{track.name}")
puts("Track location: #{track.location}")
end
# Open the file and read in the tracks then print them
def main()
file = File.new("track.txt","r")
track = read_track(file)
file.close
print_track(track)
end
main if __FILE__== $0 # need this for the testing
CODE track.rbs
# TypeProf 0.21.3
# Classes
class Object
private
def read_track: (File a_file)-> nil
return rea
def print_track: (Track track)-> nil
def main: -> nil
end
class Track
attr_accessor name: String?
attr_accessor location: String?
def initialize: (String? name, String? location)-> void
end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!