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

Ruby Ruby Foundations Modules Extend and Include: Part 2

I am having trouble getting the code to work in Linux Ubuntu for the first lesson in the Extend and Include lesson.

When I run the program I get this error on both the extend and the include programs.

This program does not work because it has a undefined local variable or method 'name for #<Hello:0x00000....... @name=”Bob”> (NameError).

Here is the code for the Extend program:

class Hello
    def initialize(name)
        @name = name

module SayHello
    def say_hello
        puts "Hello #{name}"

hello = Hello.new("Bob")
hello.extend SayHello


2 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Put this in line 9 instead of what you have:

puts "Hello #{@name}"

Watch the video again, it's around 0:28.

Thank you! That was what I was missing. I looked over the code many times and missed that symbol every time.