Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > removing mixin methods

Reply
Thread Tools

removing mixin methods

 
 
dc
Guest
Posts: n/a
 
      10-31-2008
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
 
Reply With Quote
 
 
 
 
Mike Gold
Guest
Posts: n/a
 
      10-31-2008
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/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mixin module with class variables and class methods John Lane Ruby 6 02-09-2010 09:48 PM
How to get class' filepath from methods in included mixin? Nigel Hennan Ruby 2 05-07-2009 01:08 AM
Overriding methods in a class using a mixin James Coglan Ruby 4 11-15-2008 05:01 PM
Mixin of class methods? Michael Roth Ruby 8 09-26-2005 08:00 AM
Extract methods in a class to mixin? Florian Frank Ruby 0 09-10-2003 01:20 PM



Advertisments