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 trialAnterrio Howard
2,625 PointsHelp with Bank accounts
Create an initialize method for the BankAccount class that takes one argument, name, which sets @name as an instance variable on initialization.
BankAccount = Class.new
BankAccount = Class.new
1 Answer
Jeff Muday
Treehouse Moderator 28,722 PointsYou might want to re-watch the video explaining Ruby classes. Ruby is a very nicely laid out and logical language. It is worthwhile to learn and Treehouse has some great courses to learn it!
To define a class in Ruby, you use the "class" keyword and make sure to use the "end" keyword to make the closure of the class.
class BankAccount
end
The second part of the challenge is asking for you to create a function called "initialize" for BankAccount.
1 The "initialize" needs to accept a parameter called "name".
2 the parameter needs to be assigned to the class variable name (@name)
3 finally, create a new class array called @transactions
class BankAccount
def initialize(name)
@name = name
@transactions = Array.new
end
end
Anterrio Howard
2,625 PointsAnterrio Howard
2,625 PointsJeff Muday
Will do! Thanks for your help.