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.

Leave a Reply

Comment moderation is enabled. Your comment may take some time to appear.