Skip to content

Instantly share code, notes, and snippets.

@vanderhoop
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save vanderhoop/f0d3c10bf6e707223a9e to your computer and use it in GitHub Desktop.

Select an option

Save vanderhoop/f0d3c10bf6e707223a9e to your computer and use it in GitHub Desktop.

Redefining The Student Class

You just learned how to avoid repeating yourself by using class inheritance. Now you've been tasked with putting that knowledge to use.

Directions

  1. Within ~/dev/wdi/godot/w02/d04/student/wdi_the_program/, create a file called student.rb
  2. Within student.rb, define a barebones Student class and make it inherit the behaviors of the Human class
  3. In main.rb, use require_relative to bring in the code from student.rb
  • Note: Make sure you require the student.rb file after you've required human.rb, because the former is going to rely on the class definition in the latter.
  1. Great, now instantiate a student object in main.rb and assign it to a sensibly-named variable. Then use some of the behaviors your student inherited from the Human class (for example, speak and shout) to make sure it worked.
  • Don't move on until Human behaviors work for your student object.
  1. Upon instantiation, give every Student an attribute called homeworks assigned to an empty array.
  • provide a getter for homeworks
  1. Provide instances of the Student class with the ability to do_homework. do_homework should take a single argument and push whatever gets passed in as an argument into the student's homeworks array.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment