Journal Archives About Books Talks
journal

Quick tip: Use APIdock to hunt down missing methods

From time to time, we all to have step into older projects and add features. Suddenly that old standby method you'd come to love is giving you a method_missing. How do you go about finding out which version of Rails introduced it so you can upgrade or monkey patch? APIdock has your back.

I bring this up because all too many gems depend on Active Support from Rails and introducing a new gem into an older Rails project can lead to some headaches when Active Support versions collide.

A real world example

My LinkedIn gem depends on ROXML which in turn depends on Active Support, and more specifically Object#present?. If you don't know present? is just the opposite of blank?. Never one to eschew the unless conditional (I know, I'm a heretic) I've always used unless foo.blank? and didn't notice when present? was added.

So when asked to debug my gem in an older project the error message was puzzling: undefined method `present?' for "status":String

String in this case is just a red herring. How do I know that? (Pretend for a minute you don't use present? all the time or that you're a noob). A quick search on APIdock tells us that Active Support added this method in version 2.2.1.

present? (Object) - APIdock

I know this because the navigation is enabled for this method starting in 2.2.1. So, mystery solved. My friend can now monkey patch his way out of this one or upgrade to a later version of Active Support. Pick your poison.

# Posted on