Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Ruby Booleans Build a Simple Todo List Program Part 4: Removing Todo Items

todo_item.name. Is name a method?

none

1 Answer

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 48,565 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
  @name
end

def todo_items
  @todo_items
end

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:

http://www.rubyist.net/~slagell/ruby/accessors.html

Best,

Clayton

oh ok thanks