# Removing mixin methods

**URL:** <https://www.ruby-forum.com/t/removing-mixin-methods/152255>\
**Category:** Ruby\
**Created:** [October 31, 2008, 8:55pm UTC](https://www.ruby-forum.com/t/removing-mixin-methods/152255 "2008-10-31T20:55:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 31, 2008, 8:55pm UTC](https://www.ruby-forum.com/t/removing-mixin-methods/152255/1 "2008-10-31T20:55:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 31, 2008, 9:39pm UTC](https://www.ruby-forum.com/t/removing-mixin-methods/152255/2 "2008-10-31T21:39:44Z")

</div>

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”]}
