class_eval do {nothing}?

G

Giles Bowkett

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.
 
D

dblack

Hi --

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

--
* Books:
RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242)
RUBY FOR RAILS (http://www.manning.com/black)
* Ruby/Rails training
& consulting: Ruby Power and Light, LLC (http://www.rubypal.com)
 
G

Giles Bowkett

I'm attempting to redefine existing methods with class_eval() and
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,266
Messages
2,571,318
Members
48,002
Latest member
EttaPfeffe

Latest Threads

Top