Skip to content

Instantly share code, notes, and snippets.

@darinthompson
Created December 11, 2015 16:17
Show Gist options
  • Save darinthompson/b6ce19072ea7cdcd99d8 to your computer and use it in GitHub Desktop.
Save darinthompson/b6ce19072ea7cdcd99d8 to your computer and use it in GitHub Desktop.
Random simply bit of text. Cant seem to figure out the difference
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