Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #Classes
  2.  
  3. class List
  4. attr_reader :all_tasks
  5. #Actions
  6. def initialize
  7. @all_tasks=[]
  8. end
  9. def add_task(task)
  10. all_tasks << task
  11. end
  12. def show_list
  13. all_tasks.each{|task| puts task.to_s}
  14. end
  15. end
  16.  
  17. class Task
  18. attr_reader :description
  19. def initialize(description)
  20. @description =description
  21.  
  22. end
  23. end
  24.  
  25. if __FILE__ == $PROGRAM_NAME
  26. my_list = List.new
  27. puts 'You have created a new list'
  28. my_list.add_task(Task.new("Make a Breakfast"))
  29. my_list.add_task(Task.new("Readinng Java"))
  30. my_list.add_task(Task.new("Programming Ruby"))
  31. my_list.add_task(Task.new("Sleeping"))
  32. if my_list.show_list.join.include?('#<')
  33. print [
  34. 'Are you sure you are handling your task object correctly for showing',
  35. "as a string?\n"
  36. ]
  37. end
  38. puts 'Your task list:'
  39.  
  40. my_list.show_list
  41.  
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement