Afficher un message
Vieux 15/09/2007, 18h49   #1
Joel VanderWerf
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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

  Réponse avec citation
 
Page generated in 0,06014 seconds with 9 queries