Article Image

Recently I noticed that the present? method was exhibiting weird behaviour on one of our models.
 => false # wut!?


After the initial panic wears off, the sane thing to do in this situation is to find out what present? is actually doing. Fortunately, Ruby 1.9+ allows us to find exactly where a method is defined: source_location !
 => [".../gems/activesupport-4.1.12/lib/active_support/core_ext/object/blank.rb", 16]

So far so good. present? is defined by ActiveSupport just like we expect it to be. But let’s confirm ActiveSupport’s definition.

def present?

def blank?
  respond_to?(:empty?) ? !!empty? : !self

And now back to our console again…
 => [".../app/models/chapter.rb", 25]

Aha! We do indeed have a bogus re-definition of ActiveSupport. A quick fix later and everything is behaving normally.
 => true


In a big app with lots of gems it can be hard to know exactly where a method is defined, especially since it can be overwritten and redefined numerous times. Ruby, as always, makes it easy.

Blog Logo

Seth Jeffery



Quipper Tech Team

We make amazing things.