README.md in trace_eval-0.1.4 vs README.md in trace_eval-0.1.5

- old
+ new

@@ -1,9 +1,24 @@ # TraceEval Evaluates the Ruby expression(s) in string and prints each executing line. +The standard ruby `tracer` does not display the source inside an `eval`: + +``` +$ ruby -rtracer foo.rb +#0:foo.rb:1::-: puts 1+2 +3 +#0:foo.rb:2::-: eval "puts 3+4\nputs 5+6\n" +#0:(eval):1::-: - +7 +#0:(eval):2::-: - +11 +#0:foo.rb:3::-: puts 7+8 +15 +``` + ## Installation Add this line to your application's Gemfile: ```ruby @@ -29,9 +44,50 @@ b = 2 puts a+b 4 => nil ``` + +### Bugs + +If the traced eval in turn evals, the trace will be nonsense: + +``` +irb(main):001:0> extend TraceEval +=> main +irb(main):002:0> trace_eval "0+1\neval \"2+3\n4+5\n\"\n6+7\n" +0+1 +eval "2+3 +0+1 +eval "2+3 +6+7 +=> 13 +``` + +Nested `trace_eval` does work: + +``` +irb(main):001:0> extend TraceEval +=> main +irb(main):002:0> trace_eval "0+1\ntrace_eval \"2+3\n4+5\n\"\n6+7\n" +0+1 +trace_eval "2+3 +2+3 +4+5 +6+7 +=> 13 +``` + +## Concept of Operation + +- Save a random value in a magic variable to distinguish this eval + from others +- Save an array of the lines of the eval string +- Set a `TracePoint` for `:line` events (execute code on a new line) +- When the trace point is activated + - Only proceed if the line's `path` is '(eval)' + - Only proceed if the magic variable matches the expected value + - Print the appropriate line from the array by `lineno` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run