pachl wrote: > I'm not sure how to explain what I'm looking for so I will show you: > > # this works, but not quite the functionality I need > > def simulate_cgi_upload > class << cgi_file = Tempfile.new('simulate-cgi') > def content_type() 'image/jpeg' end > end > cgi_file > end > > > # this does NOT work, but has the functionality I need > # i.e.: dynamically defining content_type's return value using > # the argument from simulate_cgi_upload method. > > def simulate_cgi_upload(mime_type = 'image/jpeg') > class << cgi_file = Tempfile.new('simulate-cgi') > def content_type() mime_type end > end > cgi_file > end Well, you need a closure, which is not the case in what you would like. The following code seems to do what you're looking for, just adapt it: def a(a) b = Object.new c = Module.new c.send(:define_method,:a) do # needed as define_method is private return a end b.extend(c) end a = a('biniou') p a.a # -> "biniou" Cheers, Vince -- Vincent Fourmond, PhD student http://vincent.fourmond.neuf.fr/