Here’s a puzzle. There must be a cleaner way to do this.
I would like to have users of this class be able to call “set_wrapper”
and define pre and post behavior on the “working” method. The only
simple way I’ve found is evaling a string the redefines “working”.
Searching threads on instance and class_eval tends to turn up an oil
slick of arguments and misinformation. Help is apprecaited!
class Thing def set_wrapper(string) eval(string) end def working yield end def main working do p 'test' end end end a = Thing.new a.main a.set_wrapper("def working; p 'pre'; yield; p 'post'; end") a.main