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 trial

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

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.