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 trial

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Creating Methods in Tests

How does the options hash actually work?

I am not fully understanding how the options hash is working within the create_todo_list method. I understand that the method is taking a parameter ( ) but not entirely sure what options={} is doing other than creating a hash.

def create_todo_list(options={})
    options[:title] ||= "My todo list" #If we do not send in title, it's going to default be My todo list
    options[:description] ||= "This is my todo list."

    visit "/todo_lists"
    click_link "New Todo list"
    expect(page).to have_content("New todo_list")

    fill_in "Title", with: options[:title]
    fill_in "Description", with: options[:description]
    click_button "Create Todo list"

1 Answer

Zachary Green
Zachary Green
16,359 Points

by setting the parameter to a default value you dont always have to pass in that parameter when using the function. its like saying if the options hash is set then use it else set options to an empty hash.