Created
December 11, 2015 16:17
-
-
Save darinthompson/b6ce19072ea7cdcd99d8 to your computer and use it in GitHub Desktop.
Random simply bit of text. Cant seem to figure out the difference
This file contains 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_item" | |
class TodoList | |
attr_reader = :name, :todo_items | |
def initialize(name) | |
@name = name | |
@todo_items = [ ] | |
end | |
def add_item(name) | |
todo_items.push(TodoItem.new(name)) | |
end | |
end | |
todo_list = TodoList.new("Groceries") | |
todo_list.add_item("Milk") | |
todo_list.add_item("Eggs") | |
puts todo_list.inspect | |
=begin | |
require "./todo_item" | |
class TodoList | |
attr_reader :name, :todo_items | |
def initialize(name) | |
@name = name | |
@todo_items = [] | |
end | |
def add_item(name) | |
todo_items.push(TodoItem.new(name)) | |
end | |
end | |
todo_list = TodoList.new("Groceries") | |
todo_list.add_item("Milk") | |
todo_list.add_item("Eggs") | |
puts todo_list.inspect | |
=end | |
The commented out code for some reason works, but the non commented out part doesn't work, | |
UNLESS you add an @ to the todo_items in the add_item method | |
Am I going crazy, or am I missing some so simple? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment