Created
November 18, 2014 00:45
-
-
Save jasonblanchard/047603c654821e42de4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require './todo' | |
| require './todos_list' | |
| todo1 = Todo.new("View RailsGuides", true, :high) | |
| todo2 = Todo.new("Check out the Stack Overflow ruby-on-rails tag", false, :high) | |
| todo3 = Todo.new("Watch 'Game of Thrones' because the books are just too long", true) | |
| todo4 = Todo.new("Read 'Hitchhiker's Guide to the Galaxy'", false) | |
| todos = [todo1, todo2, todo3, todo4] | |
| todo_list = TodosList.new(todos) | |
| todo_list.high_priority_todos | |
| puts "\n" | |
| todo_list.low_priority_todos |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Todo | |
| attr_accessor :content, :complete, :priority | |
| def initialize(content, complete, priority=:low) # Here, we are defaulting the priority argument to :low and making it optional | |
| @content = content | |
| @complete = complete | |
| @priority = priority | |
| end | |
| def show_content | |
| puts "I really need to #{@content}" | |
| end | |
| def complete? | |
| @complete | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TodosList | |
| attr_accessor :todos | |
| def initialize(todos) | |
| @todos = todos | |
| end | |
| def list_all_todos | |
| @todos.each do |todo| | |
| puts todo.content | |
| end | |
| end | |
| def list_complete_todos | |
| puts "I have already accomplished:" | |
| @todos.each do |todo| | |
| if todo.complete? == true | |
| puts todo.content | |
| end | |
| end | |
| end | |
| def list_incomplete_todos | |
| puts "I still need to:" | |
| @todos.each do |todo| | |
| if todo.complete? == false | |
| puts todo.content | |
| end | |
| end | |
| end | |
| def high_priority_todos | |
| puts "High priorities:" | |
| @todos.each do |todo| | |
| if todo.priority == :high | |
| if todo.complete? | |
| status = "complete" | |
| else | |
| status = "incomplete" | |
| end | |
| puts "#{todo.content} - #{status}" | |
| end | |
| end | |
| end | |
| def low_priority_todos | |
| puts "Low priorities:" | |
| @todos.each do |todo| | |
| if todo.priority == :low | |
| if todo.complete? | |
| status = "complete" | |
| else | |
| status = "incomplete" | |
| end | |
| puts "#{todo.content} - #{status}" | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment