From: 7stud -- Date: 2009-02-22T05:28:24+09:00 Subject: Re: How to call a module method dynamically Adrian Klingel wrote: > Yeah, that's definitely new to me. Thanks stud. Me too. Can anyone explain why I can do this: num = 1 puts Object.module_eval("num") #=>1 def f "xyz" end puts Object.module_eval("f") #=>xyz but I can't do this: module Foo def mymethod "xyz" end end puts Foo.module_eval("mymethod") --output:-- `module_eval': undefined local variable or method `mymethod' for Foo:Module (NameError) That result and the result from my previous example seem to imply that free standing def's are added to Object's singleton class, i.e. they are class methods. But in pickaxe2, p.346 it says: ------- Outside a class or module definition, a definition with an unadorned method name is added as a private method to class Object, and hence may be called in any context without an explicit receiver. ------- -- Posted via http://www.ruby-forum.com/.