From: Ross Shaw Date: 2001-05-02T20:41:23+09:00 Subject: [ruby-talk:14540] Re: Named parameters: Bright idea fizzles "Hal E. Fulton" wrote in message news:00b601c0d2b3$5c993fa0$01f9fea9@austin.rr.com... > One day, a semi-intelligent caveman named Hal > was thinking to himself about named parameters > in Ruby. > > He knew about the hash trick, but felt a primitive > longing for something more. > > He also knew about Named Parameters in a > Later Version of Ruby, but he hadn't caught onto > the "passage of time" concept yet. > > "Uh," he grunted as a ten-watt light-bulb appeared > over his head. "I'll just do it this way, using > instance_eval and a block." > > def myfunc(&block) > instance_eval(&block) > puts "#{a} #{b} #{c}" > end > > myfunc {a = 3; b = 5; c = 7 } > All the variables in your block will only be local within the block and therefore undefined outside the block. Make them instance variables and you will be right. def myfunc(&block) instance_eval(&block) puts "#{@a} #{@b} #{@c}" end myfunc {@a = 3; @b = 5; @c = 7 } ==> 3 5 7 Alternatively you can pass in a string to eval so it would be as below: def myfunc(eval_string) eval(eval_string) puts "#{a} #{b} #{c}" end myfunc ("a = 3; b = 5; c = 7") ==> 3 5 7 I suspect the first is what you want to do. Ross