From: "ara.t.howard" Date: 2008-08-27T00:23:19+09:00 Subject: Re: Passing a block with define_method On Aug 26, 2008, at 9:03 AM, James Coglan wrote: >> module_eval a string. > > > > I'm actually wrapping existing methods so I need to use > define_method to > retain access to the old method. Here's my (broken) code so far: > > module Continuations > def accepts_continuation(*args) > args.each do |method_name| > func = instance_method(method_name) > define_method(method_name) do |*params, &block| > value = func.bind(self).call(*params) > end > end > end > end off the top of my head (un-tested but similar will work) module Continuations Funcs = {} def Continuations.funcs() Funcs end def accepts_continuation *argv argv.each do |arg| arg = arg.to_s Funcs[arg] = instance_method(arg) module_eval <<-code def #{ arg }(*a, &b) Contiuations.funcs.bind(self).call(*a, &b end code end end end a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama