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!

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


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.