remove_const vs. Object.remove_const vs. Object.instance_eval {remove_const }

J

jko170

In order to remove a class, I have to use Object.instance_eval
{ remove_const }

Why couldn't I just use remove_const or Object.remove_const ?
 
R

Rick DeNatale

In order to remove a class, I have to use Object.instance_eval
{ remove_const }

Why couldn't I just use remove_const or Object.remove_const ?

Module#remove_const is private.

remove_const :Foo

is sent to the top-level object which is not a module.

Object.remove_const :Foo

fails because the method is private.

Object.instance_eval {remove_const :Foo}

is one way of getting around the privacy, another would be

Object.send:)remove_const :Foo}

HTH



--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
 

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
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top