dc wrote: > hi - > > trying to debug some metaprogramming, i just want to find the methods > of an object, and remove all methods created by mixins from other > modules. > > its easy enough to remove the superclass/inheritance chain, > > mm = @pet.methods - @pet.class.superclass.methods > > but is there a way to remove any methods that come from other modules > mixed in? > > thanks! > > /dc Does this help? class MyArray < Array def foo end end origins = MyArray.ancestors.inject(Hash.new) { |result, mod| result.update(mod => mod.instance_methods(false)) } require 'pp' pp origins # => {Object=>[], Enumerable=> ["select", "each_with_index", "grep", "map", "find_all", "sort_by", "collect", "detect", "max", "to_a", "sort", "partition", "any?", "include?", "reject", "zip", "find", "min", "member?", "entries", "inject", "all?"], Array=> ["concat", "push", "include?", "rassoc", "&", "compact!", "delete_at", "size", "collect!", "collect", "reverse_each", "flatten", "uniq!", "reverse", "first", "fill", "*", "insert", "reject!", "unshift", "+", "compact", "replace", "pack", "select", "at", "zip", "transpose", "to_s", "-", "eql?", "index", "pop", "uniq", "hash", "[]", "delete_if", "map!", "[]=", "|", "map", "indexes", "assoc", "<<", "last", "values_at", "length", "slice!", "reject", "each_index", "delete", "sort!", "sort", "fetch", "each", "clear", "join", "empty?", "inspect", "rindex", "flatten!", "frozen?", "shift", "<=>", "to_ary", "==", "reverse!", "slice", "to_a", "indices", "nitems"], Kernel=> ["clone", "protected_methods", "freeze", "instance_variable_set", "is_a?", "type", "methods", "=~", "send", "instance_of?", "__id__", "instance_variables", "to_s", "eql?", "dup", "hash", "private_methods", "nil?", "class", "tainted?", "singleton_methods", "extend", "instance_eval", "untaint", "__send__", "display", "method", "instance_variable_get", "object_id", "kind_of?", "inspect", "taint", "frozen?", "==", "public_methods", "id", "respond_to?", "===", "equal?", "to_a"], MyArray=>["foo"]} -- Posted via http://www.ruby-forum.com/.