Skip to content

Instantly share code, notes, and snippets.

@JoseJRVazquez
Created April 4, 2014 19:11
Show Gist options
  • Save JoseJRVazquez/9981226 to your computer and use it in GitHub Desktop.
Save JoseJRVazquez/9981226 to your computer and use it in GitHub Desktop.
Reiterting that no one is perfect, the lesson is trying to stress the importance of understanding the terms used when dealing with bugs.
The three given first are
"Throw - when an interpreter returns an error, it is known to "throw" the error.
Catch - when your code pro-actively accounts for the possibility of an error. An interpreter can throw errors, and you can write code to catch errors in your methods.
Handling - the act of catching an error in your code, and then doing something based on that error."
The lesson advises that when you get an error, read the message carefully to try to glean the solution from the statement. Ruby is supposed
to use very descriptive terms when it throws an error, and will try to advise you how best ot fix it.
Also, the lessons explains that while the message may tell you the location of the error, the error may be several lines of code that accompany the mentioned line. Dont just read the error line, read the entire method to make sure it uses the proper context.
Now this code:
def hello(name)
"Hello #{name}"
end
if passed hello("George", "Washington")
would throw error ArgumentError: wrong number of arguments (2 for 1) at you. Why, because there are two arguments being passed to the method when only one was called for.
Tried the first exercise and nailed it on the first try. Code was perfect and rspec passed it! Im shocked!
Second exercise went well, so im getting the hang of very basic methods. Which is to define the method, the number of arguments to be used, the argument result, and the end.
i am having issue with the following code: I have to fix the code beow so it pasts the tests below it
def add(a,b)
a + " plus " + b
end
describe "add" do
it "returns a string with 1 and 2 added" do
add(1,2).should eq("1 + 2 = 3")
end
it "returns a string with 5 and 7 added" do
add(5,7).should eq("5 + 7 = 12")
end
end
Its telling me my item should add up to the amounts aabove and look the same way. However, I cant make it work.
So after the chat room: I found outthat when enclosing a statement in #{} you can put both strings, variables, and operations inside of it. That was my error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment