Thursday, April 16, 2015

How to use respond_to? with private methods

respond_to? is an awesome method for testing if an object has a given method. By default, it will return false for methods that are private. If you want to test if an object has a method regardless of its private status, you can just pass true after the method name:

respond_to?(:foo, true)