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!

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


Has the extend method changed

This is the second video i have been following when i get the error cant find variable when trying to extend a module. In the text editor the word extend is not highlighted as i would expect so has this changed since the video? Heres the code and the when i run it it says the instances variable cant find?

module Tracking

    def instances
    @instances ||= []
class Customer
extend Tracking
    attr_reader :name

    def initialize(name)
    @name = name

    def to_s

It's tricky to help without knowing exactly how you're calling the 'instances' method, and what exact error message you're getting.

The way 'extend' works hasn't changed, but I'm wondering if you're not calling the 'instances' method on an instance of Customer and not on the Customer class itself.

The 'extend' keyword adds class methods, and not instance methods. Because this code calls 'instances' on an instance of Customer (and not on Customer itself), it will return a NoMethodError and tell you the 'instances' method is undefined:

new_customer = Customer.new("Greg")

However, this code will work just fine: