lundi 23 mai 2016

Is there an easy way to output if statements to STDOUT for debugging?

Let's say I have a decently complex if statement:

if (f_request <= mmt and f_request >= mt) and (t_request >= s)

is there a way to wrap it around a puts statement or the like to print out the logic, but instead of the variable names, their values?

For instance rather than having to type:

puts "if (#{f_request} <= #{mmt} and #{f_request} >= #{mt}) and (#{t_request} >= #{s})"

I could run some method on the original logic (or some simple way to just copy paste it into a method custom method) like:

print_logic("if (f_request <= mmt and f_request >= mt) and (t_request >= s)")

so that I could get output like:

if (6 <= 54 and 6 >= 4) and (3 >= 25000)

So I can clearly see how the logic is working and perhaps return the truthness/falseness of the logic as well.

Seems like something that could make debugging a lot easier than using p or puts to dump variables or having to construct long strings with the logic operators embedded in it.

Thanks

Aucun commentaire:

Enregistrer un commentaire