Hi --

On Wed, 19 Aug 2009, Jason Lillywhite wrote:

> I just realized that this might work:
>
> irb(main):073:0> (1.public_methods - Object.public_methods).sort
> => ["%", "&", "*", "**", "+", "+@", "-", "-@", "/", "<<", ">>", "[]",
> "^", "_orig_div", "_orig_mul", "abs", "angle", "arg", "between?",
> "ceil", "chr", "coerce", "conj", "conjugate", "denominator", "div",
> "divmod", "downto", "even?", "fdiv", "floor", "gcd", "id2name", "im",
> "imag", "image", "integer?", "lcm", "modulo", "next", "nonzero?",
> "numerator", "odd?", "ord", "polar", "prec", "prec_f", "prec_i", "pred",
> "quo", "real", "remainder", "round", "singleton_method_added", "size",
> "step", "succ", "times", "to_f", "to_i", "to_int", "to_sym", "truncate",
> "upto", "zero?", "|", "~"]
>
> So if you do 1.public_methods it shows you instance methods because 1 is
> an instance of the class Integer. If you do Integer, this is just the
> class so it will only look at class methods.
>
> Is this the best way to get the list of unique methods for Integer,
> including instance methods?

You can use the 'false' flag:

   Integer.instance_methods(false)
   Integer.methods(false)

That will give only the methods actually defined in Integer (instance
and class methods, respectively).


David

-- 
David A. Black / Ruby Power and Light, LLC / http://www.rubypal.com
Q: What's the best way to get a really solid knowledge of Ruby?
A: Come to our Ruby training in Edison, New Jersey, September 14-17!
    Instructors: David A. Black and Erik Kastner
    More info and registration: http://rubyurl.com/vmzN