Answered step by step
Verified Expert Solution
Link Copied!

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

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions