I'm trying to debug a ruby application where I loop through a bunch of days and check against my employees to see whether they worked that day. The code I am working on looks like the following:
def search_for_worked(day)
# debugger
workers = employees.select do |employee|
employee.worked?(day)
end
if workers.length < 1
raise Error
end
I know my employee.worked? method is doing something it shouldn't be and I would like to step into it with the params that are causing the problem. However the search_for_worked method is being called ~100 times before it is getting to the day where it is failing.
I can call catch Error but it halts after the method so I can't step into it.
Whats the best way to debug logic errors if I only know its doing something wrong after I've already called it?
worked?method?irbsession at yourif workers.length < 1. You can then exitirband it will pick up the program where it left off.employees.any? {|employee| employee.worked?(day)}. That way, the method would returntrueif any employees worked; elsenil. If you haveif(search_for_worked(day))..., returningnilhas the same effect as returningfalse.