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.


Pushing an instance variable to a class variable?

I just went through the Methods deep dive and feel I am getting a good understanding of what was going on. I am trying to add something to my BankAccount class. We make a create_for Class method, but if we were to create an instance of the class without using the class method, lets say it is:

new_account = BankAccount.new("joe","namath")

we would create a new instance of the Class BankAccount BUT it is not added in our array @accounts. The only way of getting it into this would be using .create_for

How can I append/add new_account into the @accounts array?

1 Answer

Jason Seifer
Jason Seifer
Treehouse Guest Teacher

Hey Scooter D you're absolutely right! In this instance, we're defining an interface of our BankAccount class to work a certain way. You could also append that instance in the initialize method if you chose. In this case, if you're working with a lot of people on this project, you'd want to document why you did it and attempt to make people follow that API.