Skip to content

Instantly share code, notes, and snippets.

@schneems
Last active December 19, 2022 13:54
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save schneems/003de3b80e6b983c84ebc7273fd60947 to your computer and use it in GitHub Desktop.
Save schneems/003de3b80e6b983c84ebc7273fd60947 to your computer and use it in GitHub Desktop.
trace where Ruby objects come from with this handy bash 3 liner
echo 'require "objspace"; ObjectSpace.trace_object_allocations_start; Kernel.send(:define_method, :sup) do |obj| ; puts "#{ ObjectSpace.allocation_sourcefile(obj) }:#{ ObjectSpace.allocation_sourceline(obj) }"; end' > tmp/tmp-gemfile
cat Gemfile >> tmp/tmp-gemfile
cat tmp/tmp-gemfile > Gemfile
# $ bundle exec irb
# irb(main):001:0> require 'rails'
# => true
# irb(main):002:0> sup(Rails)
# /Users/richardschneeman/.gem/ruby/2.4.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment