-
Notifications
You must be signed in to change notification settings - Fork 2
Ruby program runs with unexpected results
Sean Lerner edited this page Apr 21, 2017
·
3 revisions
In a way, a program is simply a series of steps that continually transforms state. When you encounter unexpected results, it means that the program at some point is transforming the current state in a way that you do not fully understand.
Use the following techniques to try to solve the issue:
- follow the flow of your program's execution
- think about the scope of any variables you're working with (local, instance, class, global)
- think about methods you are calling, and what (if any), arguments you're providing those methods
- think about the results methods are returning
- think about the datatypes that you're working with
- use
puts
debugging - use
binding.pry
andbinding.irb
to intercept and inspect your code as it's executing - try working out the issue inside of a REPL (
irb
orpry
) - use
inspect
to look inside of an object - use
raise
to cause a runtime error - try to reproduce what you're trying to achieve in the simplest way possible, and when you have that working, incorporate it into you bigger project
This is a living document. If you have anything to add, change or remove, please let us know. Or better yet, as it's a wiki, make the change yourself!