Skip to content

Instantly share code, notes, and snippets.

@brittanmcg
Last active January 1, 2016 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brittanmcg/8215628 to your computer and use it in GitHub Desktop.
Save brittanmcg/8215628 to your computer and use it in GitHub Desktop.
Shopping list app
class List
def initialize
@items = []
end
def add_item(*var)
@items << var
@items.flatten!
end
def delete_item(*var)
@items.delete(*var) #I'm having some issues here with deleting multiple items.
end
def favorite_item(*fav)
@favs = []
@favs << fav
end
def print_favs
p @favs
end
def print_list
p @items
end
def add_store
end
end
Chaps_list = List.new
Chaps_list.add_item("bacon")
#p Chaps_list
Chaps_list.add_item("dog food", "tomatoes", "paper towels")
#p Chaps_list
Chaps_list.delete_item("paper towels")
#p Chaps_list
Chaps_list.favorite_item("coffee", "toilet paper")
Chaps_list.print_favs
Chaps_list.favorite_item("dog food", "bananas") #I'm not sure why this method is not holding these items in this array permanantly.
Chaps_list.print_favs
Chaps_list.print_list
# Your Driver Code goes here...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment