January 2024
Intermediate to advanced
718 pages
20h 15m
English
While we’re having fun reflecting on all the objects and classes in our programs, let’s not forget about the humble expressions that make our code actually do things. It turns out that Ruby lets us look at these expressions, too.
First, you can watch the interpreter as it executes code, using the TracePoint class. TracePoint is used to execute a proc while adding all sorts of juicy debugging information whenever a new source line is executed, methods are called, objects are created, and so on.
Here’s a bit of what TracePoint can do (run this in your own irb window, but be aware that it’ll produce a lot of output):
| | class Test |
| | def test |
| | a = 1 |
| | end |
| | end |
| | |
| | TracePoint.trace(:line) do |trace_point| ... |
Read now
Unlock full access