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 trialMohammed Ali
11,134 Pointsto_s error
I keep getting error when I try to over ride to_s method by defining the method" def to_s ... it keeps throwing error : undefined local variable or method name - NameError! I don't get that since it seems no else seems to have had same issue.. am stuck let me know plz if you know what the issue is.. Thanks
2 Answers
Mohammed Ali
11,134 PointsIt works when I do like this, use instance var directly
def to_s
"Name: #{@name}, Balance: #{sprintf("%.2f", balance)}"
end
but not when I do like this, it's var name that's the issue not the to_s as I thought first.
def to_s
"Name: #{name}, Balance: #{sprintf("%.2f", balance)}"
end
Mohammed Ali
11,134 Pointsgot it...it's all good now. I forgot the attr_reader !!