From: Gavin Kistner Date: 2005-07-20T00:37:05+09:00 Subject: Instance Eval of a Proc Why can I not use a Proc created from a method in #instance_eval? (Or rather, am I making a mistake, or is there a way to do this?) Related: are first-class functions planned for 2.0? The whole Proc/ block/method situation needs unifying and simplifying, IMHO. [Slim:~/Desktop] gavinkis% cat instance_eval_proc.rb class Foo def self.show_name( *args ) puts "Foo.show_name says that @name is '#@name' for # {self.inspect}" end def initialize( name ) @name = name end end f = Foo.new( "Jim" ) my_lambda = lambda{ puts "my_lambda says that @name is '#@name' for #{self.inspect}" } p my_lambda f.instance_eval( &my_lambda ) my_proc = Proc.new{ puts "my_proc says that @name is '#@name' for #{self.inspect}" } p my_proc f.instance_eval( &my_proc ) meth_lambda = Foo.method( :show_name ).to_proc p meth_lambda f.instance_eval( &meth_lambda ) [Slim:~/Desktop] gavinkis% ruby instance_eval_proc.rb # my_lambda says that @name is 'Jim' for # # my_proc says that @name is 'Jim' for # # Foo.show_name says that @name is '' for Foo [Slim:~/Desktop] gavinkis% ruby --version ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0.0] [Slim:~/Desktop] gavinkis% uname -a Darwin Slim.local 8.2.0 Darwin Kernel Version 8.2.0: Fri Jun 24 17:46:54 PDT 2005; root:xnu-792.2.4.obj~3/RELEASE_PPC Power Macintosh powerpc