From: Joel VanderWerf Date: 2008-05-17T08:18:08+09:00 Subject: Re: Easy way to use "self" in Proc Leon Bogaert wrote: > Hi all, > > I have this piece of code: http://pastie.caboo.se/198524 > I'm trying to use the "self" context of the instanciated class in the > Proc. I've got it working now, but isn't there a nicer way to use the > Proc.new() without having to use the "|obj|" part? > > So instead of: > > t.code = Proc.new { |obj| obj.instance_test() } > > I want to use something like: > t.code = Proc.new { self.instance_test() } > > I've tried some stuff but I can't / don't think I can get it working the > second way. Does anyone have some bright ideas about solving this > problem? Fortunately, it's easy: t.code = Proc.new { self.instance_test() } and instead of t.code.call(obj) you just do this obj.instance_eval(&t.code) -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407