Afficher un message
Vieux 15/09/2007, 14h43   #3
Dan Zwell
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

Morton Goldberg wrote:
> On Sep 15, 2007, at 7:11 AM, Dan Zwell wrote:
>
>> Here you go:
>> def print_val(str)
>> puts "#{str} is #{eval(str)}"
>> end

>
> That didn't work for me. I had modify it like so:
>
> foo = [1, 2, 3, 4, 5]
> def print_val(str)
> puts "#{str} is #{eval(str, TOPLEVEL_BINDING)}"
> end
> print_val("foo[3] + 1")
>
> Regards, Morton
>
>


You're right, thanks. When I tested this, I used the first poster's
variable name, "Array". So it worked for me, but only because I happened
to use a name with global slope.

Dan

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