2. Strings and Regular Expressions

2. Strings and Regular Expressions

Check the documentation on String and Regexp as they could help tremendously with these exercises. For future reference as well, check out https://rubular.com/ for regex related queries. :-)

  1. Define a method hello(name) that takes a string representing a name and returns the string “Hello, “ concatenated with the name. Run associated tests via: $ rspec -e '#hello' spec/part2_spec.rb (Make sure you are in the correct directory: cd assignment)
  1. Define a method starts_with_consonant?(s) that takes a string and returns true if it starts with a consonant and false otherwise. (For our purposes, a consonant is any English letter other than A, E, I, O, U.) Make sure it works for both upper and lower case and for non-letters. Run associated tests via: $ rspec -e '#starts_with_consonant?' spec/part2_spec.rb
  1. Define a method binary_multiple_of_4?(s) that takes a string and returns true if the string represents a binary number that is a multiple of 4, such as ‘1000’. Make sure it returns false if the string is not a valid binary number. Run associated tests via: $ rspec -e '#binary_multiple_of_4?' spec/part2_spec.rb

You can check your progress on all of the above by running $ rspec spec/part2_spec.rb.

rspec spec/part2_spec.rb

Submission (10 points)

You should now be ready to submit your assignment. Remember to run your test cases once more, then submit your files to Gradescope, Codio or whichever platform your course is using.


This site uses Just the Docs, a documentation theme for Jekyll.