# Class\_eval do {nothing}?

**URL:** <https://www.ruby-forum.com/t/class-eval-do-nothing/112163>\
**Category:** Ruby\
**Created:** [August 16, 2007, 12:20am UTC](https://www.ruby-forum.com/t/class-eval-do-nothing/112163 "2007-08-16T00:20:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [August 16, 2007, 12:20am UTC](https://www.ruby-forum.com/t/class-eval-do-nothing/112163/1 "2007-08-16T00:20:59Z")

</div>

I’m attempting to redefine existing methods with class\_eval() and  
nothing’s happening. Assuming my namespaces are right, is there  
anything else to watch out for? The methods I’m targeting are private  
instance methods. Does being private somehow shield them from  
class\_eval? I would have thought the answer was definitely no but the  
redefinition is definitely floundering.

–  
Giles B.

Blog: [http://gilesbowkett.blogspot.com](http://gilesbowkett.blogspot.com)  
Portfolio: [http://www.gilesgoatboy.org](http://www.gilesgoatboy.org)

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [August 16, 2007, 12:38am UTC](https://www.ruby-forum.com/t/class-eval-do-nothing/112163/2 "2007-08-16T00:38:00Z")

</div>

Hi –

On Thu, 16 Aug 2007, Giles B. wrote:

> I’m attempting to redefine existing methods with class\_eval() and  
> nothing’s happening. Assuming my namespaces are right, is there  
> anything else to watch out for? The methods I’m targeting are private  
> instance methods. Does being private somehow shield them from  
> class\_eval? I would have thought the answer was definitely no but the  
> redefinition is definitely floundering.

Can you show an example? I’ve tried this:

class C  
def x  
1  
end  
private :x  
end

C.class\_eval { def x; 2; end }

p C.new.x # 2

and it works OK.

David

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [August 16, 2007, 1:50am UTC](https://www.ruby-forum.com/t/class-eval-do-nothing/112163/3 "2007-08-16T01:50:08Z")

</div>

> > I’m attempting to redefine existing methods with class\_eval() and  
> > nothing’s happening. Assuming my namespaces are right, is there

> Can you show an example? I’ve tried this:

It turned out that it was a namespace thing. I tested it by changing  
the class\_eval to do a remove\_method on the methods, got method not  
found errors, and fixed the namespacing.

–  
Giles B.

Blog: [http://gilesbowkett.blogspot.com](http://gilesbowkett.blogspot.com)  
Portfolio: [http://www.gilesgoatboy.org](http://www.gilesgoatboy.org)
