Re: one line to print the statement AS WELL AS the evaluated valuelike 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
def dbg(&bl)
s = yield
puts "#{s} = #{eval(s, bl).inspect}"
end
array=[0,1,2,3]
dbg{"array[3]+1"} # ==> array[3]+1 = 4
It seems a little awkward to use both {...} and "..." around the
expression, but the {} allows the #dbg method to capture the binding of
the caller.
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
|