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 Methods Class Methods

Nicholas Lee
Nicholas Lee
12,474 Points

Wrong number of arguments?

This is what I get in my terminal when I type 2.1.1 :009 > BankAccount.create_for("nick", "Lee")

ArgumentError: wrong number of arguments (2 for 0) from /Users/nicholaslee/Desktop/newbank.rb:5:in initialize' from /Users/nicholaslee/Desktop/newbank.rb:5:innew' from /Users/nicholaslee/Desktop/newbank.rb:5:in create_for' from (irb):9 from /Users/nicholaslee/.rvm/rubies/ruby-2.1.1/bin/irb:11:in<main>' 2.1.1 :010 >

Here is my code. What's going wrong?

class BankAccount

  def self.create_for(first_name, last_name)
    @account ||= []
    @account << BankAccount.new(first_name, last_name)


    def initialize(first_name, last_name)
        @balance = 0 

        @first_name = first_name
        @last_name = last_name
    end

    def deposit(amount) 
        @balance += amount
    end

    def withdraw(amount)
        @balance -= amount
    end

2 Answers

Andrew Olson
Andrew Olson
4,028 Points

Hi Nicholas!

It looks like you've almost got it. I think you've just mis-placed an end.

Try something like this:

class BankAccount
  def self.create_for(first_name, last_name)
    @account ||= []
    @account << BankAccount.new(first_name, last_name)
  end

  def initialize(first_name, last_name)
    @balance = 0

    @first_name = first_name
    @last_name = last_name
  end

  def deposit(amount)
    @balance += amount
  end

  def withdraw(amount)
    @balance -= amount
  end
end
Nicholas Lee
Nicholas Lee
12,474 Points

I cannot seem to format it correctly.