On 19/07/06, listrecv / gmail.com <listrecv / gmail.com> wrote:
> I use IRB to explore.  Very often I type a.methods.sort, to see what an
> object can do.  The problem is, you're hit with 100 methods from Object
> (or the superclass).
>
> I've experimented with:
> a.methods - a.class.superclass.methods
> which works well for simple things
>
> but it doesn't seem to handle cases when there are a lot of included
> modules.   Any ideas on how to see the methods defined in a.class only,
> and not in any superclass or included module?

This isn't exactly the answer to your question, but I've defined a
couple of methods in my .irbrc that I've found really useful. The
first is methods aliased to methods.sort (because that's always what I
want in irb, and the overhead doesn't matter there). The second is
distinct_methods, which is all the methods that aren't inherited from
Object:

class Object
  alias_method :__methods__, :methods
  def methods
    return __methods__.sort
  end
  def distinct_methods
    (__methods__ - Object.__methods__).sort
  end
end

The latter generally produces a manageable list, so I haven't found
the need to exclude methods from included modules or superclasses.

Paul.