Skip to content

Instantly share code, notes, and snippets.

@srMarquinho
Last active January 30, 2018 13:28
Show Gist options
  • Save srMarquinho/49866fb95ee26c8dbf668acb86a4be00 to your computer and use it in GitHub Desktop.
Save srMarquinho/49866fb95ee26c8dbf668acb86a4be00 to your computer and use it in GitHub Desktop.

Here's a useful one - If you ever need to check the methods of a ruby class/module (e.g. Math or User) you can call public_methods to get the class methods and public_instance_methods to get the instance ones.

The problem with this is that you'll also get entries for everything that it inherits from too, all the way up to Object methods like is_a? and send

To get around that, because they return arrays, you can subtract the result from calling it on the base class, e.g. Math.public_methods - Module.public_methods, or User.instance_methods - ActiveRecord::Base.instance_methods

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment