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/4cc95488074dc5071e4b to your computer and use it in GitHub Desktop.

Select an option

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

Defining Classes with initialize

Exercise Objectives:

  • To get practice and build muscle memory writing class declarations
  • To get practice instantiating objects of your own design

Directions

  1. Write out class definitions outlined below:
  • a Shirt class
    • upon instantiation (meaning the creation of a new object of the Shirt class), the class's initialize method should take 3 arguments:
      • size
      • color
      • text
      • ^^^^^^within your initialize method, set these arguments to instance variables of the same name
    • instantiate a new shirt, pearl_jam_t, which is extra-large, a nicely faded black, and says "Yield Tour 1998"
    • instantiate another new shirt, hipster_plaid which is size medium, the color red, says "NO LOGO" on the back
    • instantiate another new shirt, david_beckham_jersey which is large, white, and has the text "Beckham"
  1. a Concert class - upon instantiation, the Concert class's initialize method should take 4 arguments:
    • band
    • city
    • venue
    • date - instantiate a new concert, best_night_of_life, that represents Built to Spill's performance at the Metro in Chicago on May 8th, 2005. - instantiate a new concert, embarrassing_first_concert, which took place in Milwaukee, Wisconsin in like 1998 at the Marcus Amphitheater. The band? Sugar Ray.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment