Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDavid Forero
5,492 PointsWhy do we need a todo_list variable?
Why do we need a todo_list variable?
todo_list = options[:todo_list]
4 Answers
Kenan Memis
47,314 PointsHi,
It is generally for simplicity. You can use options[:todo_list] in your code for lots of time. So using a variable as todo_list could be more readable than using options[:todo_list].
David Forero
5,492 PointsThanks
Kenan Memis
47,314 Pointsoptions[:todo_list] syntax is usd for hashes. You know hash syntax right?
Let say if you have a hash called options = {}, you can store key and value pairs in it such as
options = { :todo_list => ["egg", "apple", "milk"], :name => "David Forero"}
From this data set if you want to have the todo_list array you have to call the hash with the key (by the way, key|value pair is written as :key => value) such as:
todo_list = options[:todo_list]
=> # ["egg", "apple", "milk"]
Is it clear now?
Alexander Lee
104 PointsBringing back up this question..
In this case what is options[:todo_list] value supposed to be? Based on the update_todo_list method, the options should be blank for that key value? If so, what is the purpose of this? I am a bit confused by the todo_list after using let!. Not sure why we need to to add "todo_list: todo_list" on every test either.
```
options[:title] ||= "My todo list"
options[:description] ||= "This is my todo list."
todo_list = options[:todo_list]
options = {:title => "My todo list, :description => "This is my todo list", :todo_list = ""}
```
unless :todo_list is referencing the
```
let!(:todo_list) {TodoList.create(title: "Groceries", description: "Grocery list.")}
```
Kevin Jenkins
12,630 PointsHi David,
I struggled with this line for a while as well. When a new todo list is created, we assign it to "todo_list."
When we call update_todo_list, we need to tell capybara (which runs the tests we're writing) which Edit button to press. So we pass in "todo_list" (the same one created above) into the update_todo_list function.
Then, todo_list= options[:todo_list] sets the :todo_list passed into the update_todo_list options to the local todo_list variable (on the left of the equals). Now on line within "#todo_list_#{todo_list.id}" it can get todo_list.id and select the correct edit button.
Tough to explain. Let me know if I should try again :)
David Forero
5,492 PointsDavid Forero
5,492 PointsAlso, could you please explain the syntax, why options[:todo_list]