What's difference between class_eval and module_eval ?

  • Thread starter Kyung won Cheon
  • Start date
K

Kyung won Cheon

-- test.rb --

module M
def self.test
puts "M.test is called"
end
end

M.test
M.instance_eval { test }
M.class_eval { test }
M.module_eval { test }


--- result ---

M.test is called
M.test is called
M.test is called
M.test is called
 
P

Peña, Botp

RnJvbToga2RyZWFtOTVAZ21lcmNlLmNvLmtyIFttYWlsdG86a2RyZWFtOTVAZ21lcmNlLmNvLmty
XSANCiMgV2hhdCdzIGRpZmZlcmVuY2UgYmV0d2VlbiBjbGFzc19ldmFsIGFuZCBtb2R1bGVfZXZh
bCA/DQoNCm5vbmUuIG9uZSBpcyBqdXN0IGFuIGFsaWFzIG9mIHRoZSBvdGhlci4NCg==
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top