ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Re: class destruction (evil genius metaprogramming)
by Giles Bowkett other posts by this author
Jun 18 2007 11:08AM messages near this date
Re: class destruction (evil genius metaprogramming) | Re: class destruction (evil genius metaprogramming)
>  Here's a little demo that does pretty much that

gracias!

>  (sparing the _ methods
>  like __send__):

no mercy! no survivors!

>  class Object
>     def mask
>       puts "I'm masking a method"
>     end
>  end
> 
>  class C
>     def x
>       puts "x"
>     end
> 
>     def y
>       puts "y"
>     end
>  end
> 
>  class D < C
>     def z
>       puts "z"
>     end
>  end
> 
>  class D
>     instance_methods.reject {|m| /^_/.match(m) }.each do |m|
>       alias_method m, :mask
>     end
>  end
> 
>  C.new.x   # x
>  D.new.x   # I'm masking a method
>  D.new.z   # I'm masking a method

I tried something very similar and it failed, but I can't recall why.
I'll check this later in the day.

-- 
Giles Bowkett

Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Thread:
Giles Bowkett
Rick DeNatale
dblack
Robert Dober
dblack
Robert Dober
Giles Bowkett
dblack
Stephen Smith
Nathan Taylor-Hoover
Giles Bowkett
dblack
Giles Bowkett
Rick DeNatale
dblack
Devin Mullins
dblack
Gregory Brown
Giles Bowkett

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved