# Redefine a module function in a method

**URL:** <https://www.ruby-forum.com/t/redefine-a-module-function-in-a-method/78257>\
**Category:** Ruby\
**Created:** [December 4, 2006, 4:13pm UTC](https://www.ruby-forum.com/t/redefine-a-module-function-in-a-method/78257 "2006-12-04T16:13:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mangoosta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@mangoosta](https://www.ruby-forum.com/u/mangoosta)\
**Post date:** [December 4, 2006, 4:13pm UTC](https://www.ruby-forum.com/t/redefine-a-module-function-in-a-method/78257/1 "2006-12-04T16:13:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mangoosta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@mangoosta](https://www.ruby-forum.com/u/mangoosta)\
**Post date:** [December 4, 2006, 4:37pm UTC](https://www.ruby-forum.com/t/redefine-a-module-function-in-a-method/78257/2 "2006-12-04T16:37:34Z")

</div>

On 12/4/06, Michel C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
