[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Redefine a module function in a method

Robert Feldt

12/4/2006 3:36:00 PM

On 12/4/06, Michel Casabianca <michel.casabianca@gmail.com> wrote:
> Hi all,
>
> I would like to redefine a mofule function in a method, play with my module
> and redefine this function with original one. I can't find a way to do this
> because I can't open a module in a method.
>
Not clear if you mean something like this:

module M
def m1; 1; end
end

class C1
include M
end

p C1.new.m1

class C2
include M

def redef
M.module_eval do
define_method(:m1) {2}
end
end
end

C2.new.redef
p C1.new.m1

/Robert