my methods

A useful ruby snippet that Cameron. and I came up with last night:


class Object
  def self.my_methods
    methods - (superclass ? superclass.methods : [])
  end
  
  def my_methods
    methods - (self.class.superclass ? self.class.superclass.new.methods : [])
  end
end

This is useful for finding out what methods an object has, without including all the methods inherited from super classes.

One Response to “my methods”

  1. Jason Says:

    Thank you!! Just what I needed!!