Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Ruby Foundations Objects, Classes, and Variables Objects and Classes

Methodes dependancy

Hi, at the end of this video we are running two differents methodes: deposite & show balance.

I just don't understand why the methode "show balance" wait for the return of the methode "deposit". In my point of view we should have the balance as soon as we run the file. I guess it shouldn't but why ?

Many thanks to all, amazing platform!

Niko

3 Answers

David Curtis
David Curtis
11,301 Points

hi, if you will post the code, i will take a look and try to answer your question.

If i understand your question correctly, we do start off with a balance of 0. In the initialize method, there are 2 properties that are created: @transaction and @balance. Although this version of the file, doesn't use it, @transaction is created as an array. The second property @balance is set to 0.

If you change the @balance = 0 line, in the initialize method, to another value, the program will start of with a different balance. Each time you run the file, it will always start off with what ever balance the initialize method assigns to the @balance property.

I hope this answered your question

Wasn't the question about the method "showbalance" waiting on return of method "deposit"?

Deposit is called first and it has to complete before showbalance can start - the methods are run in sequence. Deposit pauses to take input from the screen, so until it gets an input, it cannot return. Just like the ATM will wait for you to give input before anything else happens.