From: John Joyce Date: 2007-09-16T02:13:24+09:00 Subject: Re: one line to print the statement AS WELL AS the evaluated value like in C On Sep 15, 2007, at 1:51 AM, 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 All you need is something like: puts "myArray[3] + 1 is #{myArray[3] + 1} " String interpolation. Great stuff. Of course you have to create that array first to have something in it. You could also do: puts "myArray[3] + 1 is " + (myArray[3] + 1).to_s Lots of ways, but the first one is most succinct. Ruby is very flexible! You can even go from this into a DSL with words that evaluate to expressions.