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 Ruby Booleans Build a Simple Todo List Program Part 4: Removing Todo Items

todo_item.name. Is name a method?


1 Answer

Clayton Perszyk
Clayton Perszyk
Treehouse Moderator 48,723 Points

Hey nathanielcusano,

It is indeed a method; however, it isn't explicitly defined.

I'll do my best to describe how it works.

At the top of the class, Jason added this line:

attr_reader :name, :todo_items 

This is actually creating the methods for you. Behind the scenes, Ruby, is turning this line into the following code:

def name

def todo_items

The methods being created are accessor methods, which are used to grab the value of an instance variable. There are also attr_writer, to set an instance variable, and attr_accessor, which is a combination of attr_reader and attr_writer.

Here's a link that should give you a more in depth understanding of attribute accessors:




oh ok thanks