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 trialChristopher Quinn
9,943 PointsModule - Extend
class Hello
def initialize(name)
@name = name
end
end
module SayHello
def say_hello
puts "Hello #{name}"
end
end
hello = Hello.new("Chris")
hello.extend SayHello
hello.say_hello
With these I keep getting the error " 'say_hello': undefined local variable or method 'name' for #<Hello:(HEXCODE) @name="Chris"> (NameError). Any ideas why it isn't working? It apparently works in the video "Extend and Include Part 1".
1 Answer
Gary Bates
8,612 PointsYou need to include the "@" symbol in your module SayHello on the puts "Hello #{name}" line
Your line should look like this: puts "Hello #{@name}"
Your code should work then.
Christopher Quinn
9,943 PointsChristopher Quinn
9,943 PointsThat's what I get for trying to do this on no sleep, didn't even realize I forgot it. Always helps to have a second set of eyes when you make a silly mistake :). Thanks!