From: Richard Date: 2006-12-05T08:35:06+09:00 Subject: Re: How to use a String obj both in Proc.new and for puts Hi Paul and Giles, Thank you very much for your responses. You were both great. The code with commented results appears below. I've got what I wanted using using the print_and_xxx procedure when I pass the command string as a argument, along with a argument to pass to the command. Passing the command string via the call doesn't seem to offer a way to pass in an argument to pass on to the procedure. At least, I couldn't figure out how to do it. Nevertheless, I am interested to learning more about how to apply lamda expressions Again, thank you, guys. Best wishes, Richard ======== code ========== def print_then_test(cmd_string, arg) puts cmd_string + " => (when n=#{arg})" puts (Proc.new {|n| eval cmd_string}).call(arg).to_s end print_then_test("[*1..n].join(', ')", 3) puts '====' def print_and_eval lambda { |cmd_string| puts cmd_string + " =>" puts(eval(cmd_string)) } end print_and_eval.call("[*1..3].join(', ')") =begin [*1..n].join(', ') => (when n=3) 1, 2, 3 === [*1..3].join(', ') => 1, 2, 3 =end ======================