Closed ghost closed 3 years ago
That's correct...
Let's see:
"$1 puts" ("a") % ; outputs: "a puts"
therefore:
"a puts" eval
...it's like running: a puts
, and in this case of course the symbol a
is undefined!
If you want to print the string "a", then you'd have to write "a"
:
"$1 puts" ("\"a\"") % eval
I did as like as you and 👍 Good, it puts: "a"
. However now it focused to format everything that gived in, as string:
"$1 puts" (" \"1\" ") % eval ; "1"
It puts "1"
not 1
.
Is there a formatting option which adapted for this thing?
Well... that's perfectly normal behavior for an eval function, even in other languages: if you want to evaluate strings you have to put them in double quotes, and because you are evaluating a string, you have to escape them.
Honestly I am providing eval
for completeness only, typically you'd want to use load
or require
, or at any rate evaluate string that is provided from outside, not written as a string literal...
The difference of string formatting, made duplication at whole my code. Probably there is a no real solution for this.
"$1 puts" ("a") % eval
min code throws an error:But i expected that it will prints
"a"
on screen. What is wrong?