Using Ruby's TracePoint to view a method chain
Posted on Sunday, June 19th 2016I attended RailsConf again this year with @giannafusaro and got to listen to a lot of great talks and meet some really interesting people. One of my favorite talks this year was Akira Matsuda's talk "3x Rails" SlideShare / confreaks.tv, where he talked a little about Ruby's TracePoint and how to use it to see what methods are being called under the hood when you're using convenience methods like .present?
.
One of the things he mentions is that calling .present?
on an ActiveRecord object generated an absurd number of calls, something in the 80's for the version of Rails he was running. Let's try this for ourselves.
Now we can try it out:
...using this, we find c[:calls].count
is 41. At least Rails is improving ;)