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: Difference between define_method and def method; end
by Ara T Howard other posts by this author
Oct 31 2006 8:10AM messages near this date
Difference between define_method and def method; end | Re: Difference between define_method and def method; end
On Tue, 31 Oct 2006, Rune Hammersland wrote:

>  Hello dear Rubyists.
> 
>  It was suggested on the IRC channel that I try the ML for this problem ...
> 
>  While looking at how to undefine a method, I found out that there is a 
>  difference in how define_method and the def ... end block works. Example 
>  coming up:

<snip> 

>  # Try to redefine method and call super.
>  class Child < Parent

you are not redefining the method here, you are redefining the class.  if you
simply redefine the method it does what you expect:

     harp:~ >  cat a.rb
     class Parent
        def lol() puts "P: LOL" end
     end

     class Child < Parent
        def lol() puts "C: LOL" end
     end

     c = Child.new
     Child.class_eval { undef_method :lol }

     class Child  #< Parent
        def lol
          print "LOL: "
          super
        rescue NameError =>  e
            puts e.to_s
        end
     end

     c.lol


     harp:~ >  ruby a.rb
     LOL: superclass method `lol' disabled


regards.

-a
-- 
my religion is very simple.  my religion is kindness. -- the dalai lama
Thread:
Rune Hammersland
Ara T Howard
Robert Dober
Ara T Howard
Rune Hammersland
Robert Dober
Rune Hammersland
Rune Hammersland
Timothy Goddard

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