Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Classes
- class List
- attr_reader :all_tasks
- #Actions
- def initialize
- @all_tasks=[]
- end
- def add_task(task)
- all_tasks << task
- end
- def show_list
- all_tasks.each{|task| puts task.to_s}
- end
- end
- class Task
- attr_reader :description
- def initialize(description)
- @description =description
- end
- end
- if __FILE__ == $PROGRAM_NAME
- my_list = List.new
- puts 'You have created a new list'
- my_list.add_task(Task.new("Make a Breakfast"))
- my_list.add_task(Task.new("Readinng Java"))
- my_list.add_task(Task.new("Programming Ruby"))
- my_list.add_task(Task.new("Sleeping"))
- if my_list.show_list.join.include?('#<')
- print [
- 'Are you sure you are handling your task object correctly for showing',
- "as a string?\n"
- ]
- end
- puts 'Your task list:'
- my_list.show_list
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement