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 trial

Ruby

"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?

Joe Sharp
Joe Sharp
19,791 Points

Can 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.

1 Answer

I think cux the function return that string ex: def to_s "Name: #{name}, Balance: #{sprintf("%0.2f", balance)}" end