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
|