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 Instance Methods Getting underfined method

I keep getting the following error message:

NoMethodError: undefined method `deposit' for main:Object
from (irb):3
from /usr/local/rvm/rubies/ruby-1.9.3-p392/bin/irb:16:in `<main>'

When I run bank_account = deposit(1000) from using the following code in IRB

class BankAccount
def initialize(first_name, last_name)
    @balance = 0
    @first_name = first_name
    @last_name = last_name
end

def deposit(amount)
    @balane += amount
end

def withdraw(amount)
    @balance -= amount
end 
end

What am I doing incorrectly?

Cheers

2 Answers

Tommy Morgan
STAFF
Tommy Morgan
Treehouse Guest Teacher

Niles V. McGiver -

You're trying to call deposit directly - you need to call it from a BankAccount instance. Try the following code:

bank_account = BankAccount.new("Niles", "McGiver")
bank_account.deposit(1000)

Hope that helps.

Thanks Tommy, I was calling bank_account = deposit(1000), also the code was missing a 'c' in balance for the deposit method.