Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7055879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:48:05+00:00 2026-05-28T03:48:05+00:00

Given any object I can call #public_methods and see all the methods it will

  • 0

Given any object I can call #public_methods and see all the methods it will respond to. However, I find it would sometimes be handy to get a quick list of all the public methods that are not inherited, i.e. the stuff that’s really part of this class.

I found in “Easy way to list public methods for a Ruby object” that if I use:

(Foo.public_methods - Object.public_methods).sort

I can filter out a lot of basic Ruby stuff. I’d like to be able to filter everything that was inherited all the way up the chain. If I know the parent class I can filter using it, but I’d like to come up with a generic command that could return an array of the uninherited public methods for any object.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:48:05+00:00Added an answer on May 28, 2026 at 3:48 am

    Just pass false for the inherited argument of public_methods:

    "hello".public_methods.include?(:dup) # => true
    "hello".public_methods(false).include?(:dup) # => false
    

    Not an answer to your question, but in case you didn’t know, irb does autocompletion, so it’s easy to get the list of public methods (especially if you know the beginning of the method you are looking for). Just hit tab; hitting it twice will list all possibilities (including inherited ones, though):

    > "nice".d<tab><tab>
    "nice".delete      "nice".delete!    "nice".display   "nice".downcase                 
    "nice".downcase!   "nice".dump       "nice".dup       "nice".define_singleton_method
    
    > "nice".<tab><tab>
    Display all 162 possibilities? (y or n)
    ...
    

    Using pry makes it even easier to see the methods available, broken down by level of inheritance:

    [1] pry(main)> cd "nice"
    [2] pry("nice"):1> ls
    Comparable#methods: <  <=  >  >=  between?
    String#methods: %  *  +  <<  <=>  ==  ===  =~  []  []=  ascii_only?  bytes  bytesize  byteslice  capitalize  capitalize!  casecmp  center  chars  chomp  chomp!  chop  chop!  chr  clear  codepoints  concat  count  crypt  delete  delete!  downcase  downcase!  dump  each_byte  each_char  each_codepoint  each_line  empty?  encode  encode!  encoding  end_with?  eql?  force_encoding  getbyte  gsub  gsub!  hash  hex  include?  index  insert  inspect  intern  length  lines  ljust  lstrip  lstrip!  match  next  next!  oct  ord  partition  prepend  replace  reverse  reverse!  rindex  rjust  rpartition  rstrip  rstrip!  scan  setbyte  shellescape  shellsplit  size  slice  slice!  split  squeeze  squeeze!  start_with?  strip  strip!  sub  sub!  succ  succ!  sum  swapcase  swapcase!  to_c  to_f  to_i  to_r  to_s  to_str  to_sym  tr  tr!  tr_s  tr_s!  unpack  upcase  upcase!  upto  valid_encoding?
    locals: _  _dir_  _ex_  _file_  _in_  _out_  _pry_
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way I can construct an new object from the given object
Do you generally assume that toString() on any given object has a low cost
Given a Python object of any kind, is there an easy way to get
Given an object, is there any way to get notified of when that object
Estimating how long any given task will take seems to be one of the
given e.g: scala> def pipes(strings:String*) = strings.toList.mkString(|) which I can call normally: scala> pipes(foo,
I need to call a virtual method for all classes derived from a given
Given any arbitrary, one-line string, my goal is to render it into a bitmap
given any number, what's the best way to determine it is even? how many
Given any iterable, for example: ABCDEF Treating it almost like a numeral system as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.