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 Ruby Core Enumerable

bank_account.rb:32:in `initialize': wrong number of arguments (1 for 0) (ArgumentError) from bank_account.rb:32

I get an error on line 32, been sifting through the code, can't seem to find it.

class BankAccount
    attr_reader :transactions
    include Enumerable

    def <=> (other_account)
        self.balance <=> other_account.balance
    end

    def intialize(name)
        @name = name
        @balance = 0
        @transactions = []
    end

    def deposit(amount)
        @transactions.push(amount)
    end

    def withdraw(amount)
        @transactions.push(-amount)
    end

    def balance
        @transactions.inject(0) {|sum, iterator| sum += iterator}
    end

    def each
        @transactions.each{|transaction| yield transaction}
    end
end

account1 = BankAccount.new("David Czerepak")
account1.deposit(100)
account1.withdraw(50)
account1.deposit(500)
account1.withdraw(21)

account1.each do |transaction|
    puts transaction
end

2 Answers

Hi David,

bank_account.rb:32:in `initialize': wrong number of arguments (1 for 0)

This means, you haven't define method properly called initialize, it takes zero arguments and you misspelling "intialize" in line 7, see below

    def intialize(name)
        @name = name
        @balance = 0
        @transactions = []
    end

;)

Wow, I wish notepad++ would catch the misspell ! I need to change over to Ubuntu anyways. I hate developing in windows and using notepad++ and cmd prmpt.

THANKS !