Ruby Intro
CHIP 2.5: Ruby Intro
This 3-part homework gives some basic practice in Ruby as well as getting you accustomed to making testing a regular part of your workflow.
NOTE: If you are working on a local computer, do not clone this repo to your workspace. Fork it first, then clone your fork.
Learning Goals
After completing this assignment, you will know how to:
- Write simple code that uses basic constructs in the Ruby language, including methods and arguments, conditionals, string and array manipulation, regular expressions, and basic object-oriented programming mechanisms
- Understand the Ruby project conventions for where code files and test files are located in a project’s directory hierarchy
- Run individual tests or suites of tests using the RSpec unit testing tool
- Understand the basic syntax of RSpec unit tests
Overview
You may find the Ruby documentation at ruby-doc.org helpful to have on hand.
The repo for this assignment follows a fairly standard Ruby convention for codebases: the code files are stored in lib/ and the test files are stored in spec/. (We use the RSpec unit-testing framework; if we were using Ruby’s default framework, known as Test::Unit, the test files would be under test/.)
We’ve placed “starter code” in lib/ruby_intro.rb; when you’re all done, you can submit this single file to the autograder.
However, you can test each of the 3 parts separately. The files spec/part[123]_spec.rb contain RSpec tests for each of the three parts. For example, to test your answers to Part 1, say rspec spec/part1_spec.rb. rspec with no arguments runs the tests in all the files spec/*_spec.rb.
- The line numbers in the RSpec error report will give you guidance as to which tests failed. (You can check the RSpec documentation to see how the
.rspecfile can be used to customize the output format.)
If you are working in Codio, please cd into the assignment directory and run bundle. If you are working on a local computer, proceed with the following steps.
Local computer setup
Ensure that Ruby 3.3.8 or newer is installed. To ensure you have the rspec gem installed you need bundler and can then run bundle install like so:
$ ruby -v
$ gem install bundler
$ cd assignment
$ bundle
If you do not see something like ruby 3.3.10 (2025-10-23 revision 343ea05002) [arm64-darwin24] with the version 3.3 or larger, then you should upgrade your version of Ruby before continuing. Check DEVELOPING.md for guidance, but you should be able to run mise install ruby@3.3 or rvm install 3.3, depending on which tools you have installed.
When the above completes successfully you’ll have RSpec installed and can run rspec from the command line to test your code.