Most beginner Ruby mistakes are fixable in minutes if you stop guessing. Treat every error as evidence: read it, reproduce it, change one thing, then re-run the smallest possible script. The fixes below cover the errors beginners meet most often in Ruby 3.x. The aim is not to avoid mistakes; it is to make each fix small enough to verify.
Start with the exact error message, not the line you guess
Ruby prints the file, line number, error class, and message, followed by a backtrace. Read the first three backtrace lines before editing. If the message says NoMethodError on nil, the fault is usually earlier than the line shown: a lookup returned nil or a method returned no value. Run ruby -v once and note the version, such as 3.3.0, because older tutorials may use syntax that behaves differently. If the backtrace names a gem, check that gem's version before editing your own code. Reproduce the failure in a file of under 10 lines. Fixing a small reproduction is faster and safer than changing a 200-line project.
Fix NoMethodError on nil before changing the method
user.name fails when user is nil; the method name is fine. Add a guard: return unless user or puts user&.name. Use safe navigation only when nil is an acceptable result; otherwise fail early with a clear message. For arrays, remember that indexing starts at 0, so items[0] is the first item and items[1] is the second. Check whether the value is nil, [], or ""; they behave differently. When in doubt, print user.inspect; it shows nil cleanly and reveals empty strings that look blank in output. Add one test case for the empty value and one for a real value. That two-case check catches most nil bugs before they spread.
Copy strings and arrays when you mean to change a copy
a = b gives both names the same object, not a duplicate. If b.upcase! changes a string, a changes too. Check with a.object_id == b.object_id. Use b = a.dup for a shallow copy; nested arrays still share inner objects. Prefer non-mutating methods such as upcase, map, and sort unless you deliberately want to change the original. Add # frozen_string_literal: true at the top of new files to catch accidental string mutation early. Test a copy by changing it and printing both objects; if both change, you copied the reference, not the value. Keep copies shallow unless you need deep duplication; deep copying is rarely needed in beginner scripts.
Make method arguments explicit and test three calls
A wrong argument error often means the method expects keywords, not a positional value. def greet(name:) must be called as greet(name: "Ada"); greet("Ada") raises an ArgumentError. Decide on positional arguments for one or two obvious values and keywords for anything optional or easy to confuse. If the method has more than three parameters, use a single hash or keyword arguments to make calls readable. Test three calls: a normal value, a boundary value such as 0 or "", and an invalid value. Run the file after each change. If the method returns early, print the return value with p so you can see whether it returns nil by accident.
Fix loops that never end or skip items
A while loop needs its condition changed inside the loop. If while count < 5 never changes count, it runs forever; add count += 1 and print count once per pass. Do not delete items from an array while iterating it with each; the index shifts and items are skipped. Use reject!, select!, or iterate over items.dup. Use each for side effects, map when you want a new array, and break to leave a loop early. Count your iterations with a temporary counter; if it reaches 100 for a five-item list, stop and inspect the collection. After a loop, print the final collection with p to confirm its length and contents match what you expected.
Diagnose the failure: the script runs but the answer is wrong
Symptoms: no crash, but the total is wrong, text is missing, or a value looks like the wrong type. Likely causes: a string is being added to a number, integer division is truncating, or a variable is being read outside the scope where it was set. The fix is to print types and values together. p [:value, value, value.class] shows whether you have "5" or 5. Remember that 5 / 2 returns 2, while 5.fdiv(2) returns 2.5. Convert input with to_i or to_f only after checking it is numeric. Use irb for a one-line check; type the expression, press Return, and read the class of the result. Spend 60 seconds printing three labelled values before changing logic.
Fix load and gem errors without rebuilding everything
LoadError usually means Ruby cannot find a file. Use require_relative "helper" for a file beside your script and require "json" for a standard library or installed gem. A Bundler::GemNotFound error means the bundle is incomplete or you are running the wrong command. Run bundle install once, then run the script with bundle exec ruby app.rb. Check that Gemfile.lock is present and that you are in the project folder. If the error mentions a path, print Dir.pwd and compare it with the folder that contains your script. Avoid installing random gems to fix a single error; solve the missing file or bundle first.
Keep a five-minute error log so the same bug does not return
After each fixed error, write three lines: the error message, the cause, and the one-line fix. Do this for 5 minutes, not 30. Review the log after 7 days and turn repeated entries into a tiny test script or a checklist. For example, if nil appears twice, add a guard clause to the method that supplies the value. If integer division appears twice, use fdiv in the calculation. Keep the log beside the script, not in a separate app; you will actually review it. This log turns debugging from memory into a repeatable process, which is the real beginner skill.
FAQ
Why does Ruby say undefined method when the method exists?
Usually the receiver is nil or a different class than you expect. Print receiver.class and receiver.inspect immediately before the call. If the receiver is nil, fix the source of the value rather than adding methods to NilClass.
Should I use puts or p when fixing a mistake?
Use p for debugging because it shows quotes, nil, and structure; use puts for clean output. Add labels: p [:total, total]. Remove or comment out debugging lines once the fix is confirmed.
How small should a reproduction be?
Small enough to read in under 30 seconds: aim for 5 to 10 lines. Keep only the failing value, the call, and one print statement. If the bug disappears, add the removed code back one piece at a time until it returns.