A civic-minded citizen seeking the singularity

An entry

Introspection, in Ruby

Date: 2015-10-03
Status: release
Tags: introspection metaprogramming ruby

I was curious about what an object chart, or dependency graph, looks like in a running application. One of my favorite features about ruby is its ability to introspect; to have awareness of its own state at runtime.

Using the following snippet in your development Rails 4.x application, results in a verbose log file and a tremendously slow page-load time, but provides insightful information about the lifecycle of a request in Rails.

class Application < Rails::Application set_trace_func proc { |event, file, line, id, binding, classname| printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname } end