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.
undefined method `+' ???
I followed what Jason said to deposit(1000) but I always get this:
2.2.1 :003 > bank_account.deposit(1000)
NoMethodError: undefined method
+' for nil:NilClass
from /Users/ann/.rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'
can you let me know what's wrong?
Hello! Thanks for the quick reply. This is my code here:
class BankAccount def initialize(first_name, last_name) @blance = 0 @first_name = first_name @last_name = last_name end
def deposit(amount) @balance += amount end def withdraw(amount) @balance -= amount end
Ethan LowryCourses Plus Student 7,323 Points
This error is a common one, and it means some object you're trying to call a method (in this case addition or concatenation) on is nil, rather than the string / number / whatever you're expecting it to be.
Check everywhere in your code where you're assigning things to variables and make sure everything is right and not returning nil instead of what you expect.
If this doesn't help, please post your code so we can take a look.