Table of Contents

Ruby Exercises


Exercise 1 - MU News html scraping with regular expressions

(a reprise of Python Exercise 5)

In rubyex1.rb, parse the article titles and links from the HTML source of http://www.monmouth.edu/news/archives. Store the titles and links in arrays. Use regular expressions for this version. Later, we'll use a parser.

Note: Also, dropbox rubyex1_map.rb and rubyex1_parser.rb.


Exercise 2 - A Roster class

In rubyex2.rb create and use a Roster class. The Roster class consists of an array of Student class objects (Student class shown below):

class Student
   def initialize( first, last, email )
      @first = first
      @last  = last
      @email = email
   end

   def show
      puts "#{@first}  #{@last}  #{@email}"
   end
end

Create a new Roster called cs001 that consists of the students in your roster.txt file. Write a Roster.list method to show the roster of students.


Exercise 3 - Ruby and SQLite3

See the menu-driven Ruby/SQLite3 example program that allows you to create, manipulate and search a database table:

Save it as rubyex3.rb. Add a list_all function and corresponding “4) List all records” menu item to list all existing records in the database.


Exercise 4 - Ruby on Rails mydiary sample app

Complete the mydiary Ruby on Rails mydiary sample app. Your app must contain the additions and changes that were made in class. Add at least three entries in your mydiary app. All entries must contain your name and student ID. After you are done, create a zip archive of the mydiary folder and dropbox it.