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 trialAnthony Donovan
4,650 Points"Name: #{name}, Balance: #{sprintf("%0.2f", balance)}"
How come the local variable "name" is used instead of the instance variable "@name", and it still works despite the fact that "name" as a local variable is not defined within the "balance" method?
1 Answer
jhon white
20,006 PointsI think cux the function return that string ex: def to_s "Name: #{name}, Balance: #{sprintf("%0.2f", balance)}" end
Joe Sharp
19,791 PointsJoe Sharp
19,791 PointsCan you post a link to your full code, or at least the lesson you were on? Without the context it is impossible to say what could be going on.