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
Jimmy Holway
26,589 PointsInstance Methods Syntax error loading my bank_account.rb
I'm following along in my Terminal and text editor for the Ruby Deep Dive. It looks like it's getting my .rb file correctly but throwing a syntax error. My file and the one in the video are identical as far as I can tell, but I'm a Ruby noob so.. I dunno.
When I:
load './bank_account.rb'
I get:
syntax error, unexpected '(', expecting :: or '.'
def @withdraw(amount)
Any ideas?
First one to solve help me over this speed bump gets a digital hive five.
Full error message:
load './bank_account.rb'
SyntaxError: /Volumes/DATA/Users/atotalpirate/Desktop/treehouse/Source/methods/bank_account.rb:13: syntax error, unexpected '(', expecting :: or '.'
def @withdraw(amount)
^
/Volumes/DATA/Users/atotalpirate/Desktop/treehouse/Source/methods/bank_account.rb:17: syntax error, unexpected keyword_end, expecting end-of-input
from (irb#1):1:in `load'
from (irb#1):1
2 Answers
Scooter D
9,611 PointsI'm not the best at explaining this since I am learning myself. But I had a similar issue. This is what I did.
I saved my document to my desktop, for me, this is a very easy path for me to use.
I then opened my terminal, and typed in irb (enter)
then I put this:
load 'desktop/treehouse-methods.rb'
treehouse-methods is the name of my bank account file.
After that, it returned true.
I believe the "." is saying "current director". So if you replace the "." with the same directory you saved your file in, it should work.
Hope this helps!
Scooter D
9,611 Pointsso it is returning true now? Is it working?
Jimmy Holway
26,589 PointsIt is indeed. Thanks! Your answer got me rechecking my paths which was the right direction.
Jimmy Holway
26,589 PointsNevermind. Turns out I just deleted the contents of the file and loaded to see if there was an error in my code. When I command + z'd my code back, I got that error again. Below is my code. I can't find the problem but the Terminal seems to be pointing to def @withdraw(amount).
class BankAccount
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
UPDATE:
When I remove the following code, my load returns true in irb:
def deposit(amount)
@balance += amount
end
UPDATE AGAIN:
I just decided to retype everything and for reasons I can't find, it works perfectly now. Loads true and accepts input. I can only assume a wizard is teasing me.
Jimmy Holway
26,589 PointsJimmy Holway
26,589 PointsThanks for the reply! Unfortunately this did not work for me. I tried renaming the file, every different path syntax I could think of, moving the file, scouring the contents for the smallest typo or extra whitespace (just in case?) and right now I'm shopping online for a goat to sacrifice to Gods of Computer Stuff I Don't Understand.
Scooter D
9,611 PointsScooter D
9,611 PointsDo you know what directory you saved the bank_account.rb? Desktop, Documents, Downloads, etc?
Jimmy Holway
26,589 PointsJimmy Holway
26,589 PointsI have it in Desktop/treehouse/Source/methods/bank_account.rb
I've tried exiting irb and cding into my methods folder and using load './bank_account.rb'
While typing this I tried copying my bank_account.rb to my root (cd ~) and using load './bank_account.rb' and it returned true. Does this just mean I'm stupid at paths? Gah.
Jimmy Holway
26,589 PointsJimmy Holway
26,589 Pointsload './Desktop/treehouse/Source/methods/bank_account.rb'
Is also returning true. It seems that yes. I am just stupid at paths. The goat will live to fight another day.