From: Dan Zwell Date: 2007-09-15T20:11:29+09:00 Subject: Re: one line to print the statement AS WELL AS the evaluated value like in C kendear wrote: > i wonder in Ruby, is there a line method to do something like in C > > > print_val("Array[3] + 1") > > and get the printout of > > > Array[3] + 1 is 3.345 > Here you go: def print_val(str) puts "#{str} is #{eval(str)}" end This should do what you want. Be wary of side effects, though. For example, to display the value of "a += 3" requires evaluation, and that changes the value of "a" (and when you remove this debugging line, your program no longer works the way you expect). Have fun, Dan