Home

Find the Source of a Ruby Method's "Super"

It can be helpful when debugging to know what "super" is actually calling.

I've spent part of the last couple days debugging the bowels of a pesky Rails project. The issue was the infamous Stack Level Too Deep error.

I found the source of the problem was a gem's method calling super. And while the stack trace of an error will show you the pathway of an error, sometimes it can be helpful to manually find that pathway yourself during the debugging process.

It can be done in a quick one-liner using the name of the method:

method(:method_name).super_method.to_s

Where method_name is the name of the method you want to check.

Here's a simplistic example to demonstrate:

class A
def foo
'bar'
end
end

class B < A
def foo
method(:foo).super_method.to_s
end
end

a = A.new
a.foo # => bar

b = B.new
b.foo # => #<Method: A#foo>

Let's Connect

Keep Reading

Parse a Web Page and Post to Slack Using Ruby

When another website is doing the heavy-lifting updating some content you want to keep up on, but there's no good integration with Slack, you can parse it yourself and post directly to a Slack channel.

Feb 24, 2016

Bulk Resize Images Using Rake and ImageMagick

Got a set of images you need all to conform to the same size? Hate doing it manually? Me too. Let's write a rake task to solve our challenge.

Feb 15, 2016

Inherited Class-Level Utilities in Ruby

The difference between Ruby's class and class instance variables, and how you can use them to abstract functionality from inherited classes.

Jan 14, 2017