This Year's posts

Archive for April, 2008

my methods

Wednesday, April 2nd, 2008

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.