Skip to content

Instantly share code, notes, and snippets.

@MatthiasWinkelmann
Created May 19, 2017 04:45
Show Gist options
  • Save MatthiasWinkelmann/f7bcd0ff022bce26119f23be69aa499a to your computer and use it in GitHub Desktop.
Save MatthiasWinkelmann/f7bcd0ff022bce26119f23be69aa499a to your computer and use it in GitHub Desktop.
Filter ruby's <Class>.methods to exclude the common ones
module ObjectExtensions
def methods
return super - Object.methods unless self == Object
super
end
end
class Object
prepend ObjectExtensions
end
@MatthiasWinkelmann
Copy link
Author

MatthiasWinkelmann commented May 19, 2017

You're trying to find a method in some gem's class. Or whatever. Usually, it has 200 methods, most of which are generic and probably not what you're looking for if you have any experience with ruby.

Better:

[1] pry(main)> IsoCountryCodes.methods
[
    [0]                    all()                IsoCountryCodes
    [1]                   find(code, &fallback) IsoCountryCodes
    [2]             for_select(*args)           IsoCountryCodes
    [3]                 search(term)            IsoCountryCodes
    [4]      search_by_calling(code, &fallback) IsoCountryCodes
    [5] search_by_calling_code(code, &fallback) IsoCountryCodes
    [6]     search_by_currency(code, &fallback) IsoCountryCodes
    [7]         search_by_iban(code, &fallback) IsoCountryCodes
    [8]         search_by_name(str, &fallback)  IsoCountryCodes

Before

[[3] pry(main)> IsoCountryCodes.methods
[
    [  0]                                !()                          Class (BasicObject)
    [  1]                               !=(arg1)                      Class (BasicObject)
    [  2]                               !~(arg1)                      Class (Kernel)
    [  3]                                <(arg1)                      Class (Module)
    [  4]                               <=(arg1)                      Class (Module)
    [  5]                              <=>(arg1)                      Class (Module)
    [  6]                               ==(arg1)                      Class (Module)
    [  7]                              ===(arg1)                      Class (Module)
    [  8]                               =~(arg1)                      Class (Kernel)
    [  9]                                >(arg1)                      Class (Module)
    [ 10]                               >=(arg1)                      Class (Module)
    [ 11]                      __binding__()                          Class (Object)
    [ 12]                           __id__()                          Class (BasicObject)
    [ 13]                         __send__(*arg1)                     Class (BasicObject)
    [ 14]                                `(command)                   Class (Object)
    [ 15]                       acts_like?(duck)                      Class (Object)
    [ 16]                               ai(*options)                  Class (Kernel)
    [ 17]                  alias_attribute(new_name, old_name)        Class (Module)
    [ 18]                              all()                          IsoCountryCodes
    [ 19]                         allocate()                          Class
    [ 20]                        ancestors()                          Class (Module)
    [ 21]                       anonymous?()                          Class (Module)
    [ 22]                          as_json(*options)                  Class (Object)
    [ 23]                    attr_internal(*attrs)                    Class (Module)
    [ 24]           attr_internal_accessor(*attrs)                    Class (Module)
    [ 25]             attr_internal_reader(*attrs)                    Class (Module)
    [ 26]             attr_internal_writer(*attrs)                    Class (Module)
    [ 27]                         autoload(arg1, arg2)                Class (Module)
    [ 28]                        autoload?(arg1)                      Class (Module)
    [ 29]                  awesome_inspect(*options)                  Class (Kernel)
    [ 30]                    awesome_print(object, *options)          Class (Kernel)
    [ 31]                           blank?()                          Class (Object)
    [ 32]                           byebug()                          Class (Kernel)
    [ 33]                   cattr_accessor(*syms, &blk)               Class (Module)
    [ 34]                     cattr_reader(*syms)                     Class (Module)
    [ 35]                     cattr_writer(*syms)                     Class (Module)
    [ 36]                            class()                          Class (Kernel)
    [ 37]                  class_attribute(*attrs)                    Class
    [ 38]                       class_eval(*arg1)                     Class (Module)
    [ 39]                       class_exec(*arg1)                     Class (Module)
    [ 40]          class_variable_defined?(arg1)                      Class (Module)
    [ 41]               class_variable_get(arg1)                      Class (Module)
    [ 42]               class_variable_set(arg1, arg2)                Class (Module)
    [ 43]                  class_variables(*arg1)                     Class (Module)
    [ 44]                            clone(*arg1)                     Class (Kernel)
    [ 45]                          concern(topic, &module_definition) Class (Module::Concerning)
    [ 46]                       concerning(topic, &block)             Class (Module::Concerning)
    [ 47]                   const_defined?(*arg1)                     Class (Module)
    [ 48]                        const_get(*arg1)                     Class (Module)
    [ 49]                    const_missing(const_name)                Class (ActiveSupport::Dependencies::ModuleConstMissing)
    [ 50]                        const_set(arg1, arg2)                Class (Module)
    [ 51]                        constants(*arg1)                     Class (Module)
    [ 52]                         debugger()                          Class (Kernel)
    [ 53]                         deep_dup()                          Class (Object)
    [ 54]          define_singleton_method(*arg1)                     Class (Kernel)
    [ 55]                         delegate(*methods, ?, ?, ?)         Class (Module)
    [ 56]              delegate_missing_to(target)                    Class (Module)
    [ 57]                        deprecate(*method_names)             Class (Module)
    [ 58]               deprecate_constant(*arg1)                     Class (Module)
    [ 59]                      descendants()                          Class
    [ 60]                          display(*arg1)                     Class (Kernel)
    [ 61]                              dup()                          Class (Kernel)
    [ 62]                      duplicable?()                          Class (Object)
    [ 63]                         enum_for(*arg1)                     Class (Kernel)
    [ 64]                             eql?(arg1)                      Class (Kernel)
    [ 65]                           equal?(arg1)                      Class (BasicObject)
    [ 66]                           extend(*arg1)                     Class (Kernel)
    [ 67]                             find(code, &fallback)           IsoCountryCodes
    [ 68]                       for_select(*args)                     IsoCountryCodes
    [ 69]                           freeze()                          Class (Module)
    [ 70]                          frozen?()                          Class (Kernel)
    [ 71]                              gem(dep, *reqs)                Class (Kernel)
    [ 72]              guess_for_anonymous(const_name)                Class (ActiveSupport::Dependencies::ModuleConstMissing)
    [ 73]                             hash()                          Class (Kernel)
    [ 74]                       html_safe?()                          Class (Object)
    [ 75]                              in?(another_object)            Class (Object)
    [ 76]                          include(*arg1)                     Class (Module)
    [ 77]                         include?(arg1)                      Class (Module)
    [ 78]                 included_modules()                          Class (Module)
    [ 79]                          inspect()                          Class (Module)
    [ 80]                    instance_eval(*arg1)                     Class (BasicObject)
    [ 81]                    instance_exec(*arg1)                     Class (BasicObject)
    [ 82]                  instance_method(arg1)                      Class (Module)
    [ 83]                 instance_methods(*args)                     Class
    [ 84]                     instance_of?(arg1)                      Class (Kernel)
    [ 85]                  instance_values()                          Class (Object)
    [ 86]       instance_variable_defined?(arg1)                      Class (Kernel)
    [ 87]            instance_variable_get(arg1)                      Class (Kernel)
    [ 88]          instance_variable_names()                          Class (Object)
    [ 89]            instance_variable_set(arg1, arg2)                Class (Kernel)
    [ 90]               instance_variables()                          Class (Kernel)
    [ 91]                            is_a?(arg1)                      Class (Kernel)
    [ 92]                           itself()                          Class (Kernel)
    [ 93]                  json_creatable?()                          Class
    [ 94]                         kind_of?(arg1)                      Class (Kernel)
    [ 95]                  load_dependency(file)                      Class (ActiveSupport::Dependencies::Loadable)
    [ 96]                   mattr_accessor(*syms, &blk)               Class (Module)
    [ 97]                     mattr_reader(*syms)                     Class (Module)
    [ 98]                     mattr_writer(*syms)                     Class (Module)
    [ 99]                           method(arg1)                      Class (Kernel)
    [100]                  method_defined?(arg1)                      Class (Module)
    [101]                method_visibility(method)                    Class (Module)
    [102]                          methods(*args)                     Class (Object)
    [103]                      module_eval(*arg1)                     Class (Module)
    [104]                      module_exec(*arg1)                     Class (Module)
    [105]                             name()                          Class (Module)
    [106]                              new(*arg1)                     Class
    [107]                             nil?()                          Class (Kernel)
    [108]                        object_id()                          Class (Kernel)
    [109]                           parent()                          Class (Module)
    [110]                      parent_name()                          Class (Module)
    [111]                          parents()                          Class (Module)
    [112]                          prepend(*arg1)                     Class (Module)
    [113]                         presence()                          Class (Object)
    [114]                      presence_in(another_object)            Class (Object)
    [115]                         present?()                          Class (Object)
    [116]                   pretty_inspect()                          Class (Kernel)
    [117]                     pretty_print(q)                         Class (Module)
    [118]               pretty_print_cycle(q)                         Class (Module)
    [119]             pretty_print_inspect()                          Class (PP::ObjectMixin)
    [120]  pretty_print_instance_variables()                          Class (PP::ObjectMixin)
    [121]             private_class_method(*arg1)                     Class (Module)
    [122]                 private_constant(*arg1)                     Class (Module)
    [123]         private_instance_methods(*args)                     Class
    [124]          private_method_defined?(arg1)                      Class (Module)
    [125]                  private_methods(*args)                     Class (Object)
    [126]       protected_instance_methods(*args)                     Class
    [127]        protected_method_defined?(arg1)                      Class (Module)
    [128]                protected_methods(*args)                     Class (Object)
    [129]                              pry(*object, *hash)            Class (Object)
    [130]                    psych_to_yaml(*options)                  Class (Object)
    [131]                    psych_yaml_as(url)                       Class (Module)
    [132]              public_class_method(*arg1)                     Class (Module)
    [133]                  public_constant(*arg1)                     Class (Module)
    [134]           public_instance_method(arg1)                      Class (Module)
    [135]          public_instance_methods(*args)                     Class
    [136]                    public_method(arg1)                      Class (Kernel)
    [137]           public_method_defined?(arg1)                      Class (Module)
    [138]                   public_methods(*args)                     Class (Object)
    [139]                      public_send(*arg1)                     Class (Kernel)
    [140]                   rake_extension(method)                    Class (Module)
    [141]                       reachable?()                          Class (Module)
    [142]                  redefine_method(method, &block)            Class (Module)
    [143]            remove_class_variable(arg1)                      Class (Module)
    [144]         remove_instance_variable(arg1)                      Class (Kernel)
    [145]           remove_possible_method(method)                    Class (Module)
    [146] remove_possible_singleton_method(method)                    Class (Module)
    [147]               require_dependency(file_name, *message)       Class (ActiveSupport::Dependencies::Loadable)
    [148]                  require_or_load(file_name)                 Class (ActiveSupport::Dependencies::Loadable)
    [149]                      respond_to?(*arg1)                     Class (Kernel)
    [150]                           search(term)                      IsoCountryCodes
    [151]                search_by_calling(code, &fallback)           IsoCountryCodes
    [152]           search_by_calling_code(code, &fallback)           IsoCountryCodes
    [153]               search_by_currency(code, &fallback)           IsoCountryCodes
    [154]                   search_by_iban(code, &fallback)           IsoCountryCodes
    [155]                   search_by_name(str, &fallback)            IsoCountryCodes
    [156]                             send(*arg1)                     Class (Kernel)
    [157]                  singleton_class()                          Class (Kernel)
    [158]                 singleton_class?()                          Class (Module)
    [159]                 singleton_method(arg1)                      Class (Kernel)
    [160]                singleton_methods(*args)                     Class (Object)
    [161]                       subclasses()                          Class
    [162]                       superclass()                          Class
    [163]                suppress_warnings()                          Class (Kernel)
    [164]                            taint()                          Class (Kernel)
    [165]                         tainted?()                          Class (Kernel)
    [166]                              tap()                          Class (Kernel)
    [167]            thread_cattr_accessor(*syms)                     Class (Module)
    [168]              thread_cattr_reader(*syms)                     Class (Module)
    [169]              thread_cattr_writer(*syms)                     Class (Module)
    [170]            thread_mattr_accessor(*syms)                     Class (Module)
    [171]              thread_mattr_reader(*syms)                     Class (Module)
    [172]              thread_mattr_writer(*syms)                     Class (Module)
    [173]                          to_enum(*arg1)                     Class (Kernel)
    [174]                          to_json(*options)                  Class (ActiveSupport::ToJsonWithActiveSupportEncoder)
    [175]                         to_param()                          Class (Object)
    [176]                         to_query(key)                       Class (Object)
    [177]                          to_ruby()                          Class (V8::Conversion::Object)
    [178]                             to_s()                          Class (Module)
    [179]                      to_template()                          Class (V8::Conversion::Class)
    [180]                            to_v8()                          Class (V8::Conversion::Code)
    [181]                          to_yaml(*options)                  Class (Object)
    [182]               to_yaml_properties()                          Class (Object)
    [183]                            trust()                          Class (Kernel)
    [184]                              try(*a, &b)                    Class (ActiveSupport::Tryable)
    [185]                             try!(*a, &b)                    Class (ActiveSupport::Tryable)
    [186]                       unloadable(*const_desc)               Class (ActiveSupport::Dependencies::ModuleConstMissing)
    [187]                          untaint()                          Class (Kernel)
    [188]                          untrust()                          Class (Kernel)
    [189]                       untrusted?()                          Class (Kernel)
    [190]                         weakcell(name, &block)              Class (V8::Weak::Cell)
    [191]                     with_options(options, &block)           Class (Object)
    [192]                          yaml_as(url)                       Class (Module)
    [193]                         yaml_tag(url)                       IsoCountryCodes (Object)
]

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