I think it is quite “ok”.
At least there is no extra copying (or serialization) of “val”
as in my original example.
This is probably obvious and likely irrelevant, but I will mention
that a caller could do something malicious by passing in an “evil”
string to be evaluated.
I didn’t realize that the eval would “see” the value of “val”,
but apparently it does.
It sees everything in the current binding. For example,
x = eval(“val”) is the same as x = val. (There are probably some
strange exceptions to this.)
But I’m still interested in a solution without “eval”.
My impression is that without a Ruby builtin, it is not really
possible without eval.
Exceptions might be:
Maybe an extension could implement a method to do it.
You could do something crazy like write an assignment to
a file and then require the file… but it would fail under
many circumstances.
I think it is quite “ok”.
At least there is no extra copying (or serialization) of “val”
as in my original example.
This is probably obvious and likely irrelevant, but I will mention
that a caller could do something malicious by passing in an “evil”
string to be evaluated.
I don’t want to be responsible for encouraging non-vigilance toward
things like this… but if val is a string, wouldn’t eval’ing val
just result in the string, not a further evaluation of the string?
a = “puts ‘hi’”
eval “b = a”
b is now “puts ‘hi’”, but ‘hi’ doesn’t get puts’d.
(Or is there another, more evil scenario I’m not thinking of?)
I think it is quite “ok”.
At least there is no extra copying (or serialization) of “val”
as in my original example.
This is probably obvious and likely irrelevant, but I will mention
that a caller could do something malicious by passing in an “evil”
string to be evaluated.
I don’t want to be responsible for encouraging non-vigilance toward
things like this… but if val is a string, wouldn’t eval’ing val
just result in the string, not a further evaluation of the string?
a = “puts ‘hi’”
eval “b = a”
b is now “puts ‘hi’”, but ‘hi’ doesn’t get puts’d.
(Or is there another, more evil scenario I’m not thinking of?)
I think it is quite “ok”.
At least there is no extra copying (or serialization) of “val”
as in my original example.
This is probably obvious and likely irrelevant, but I will mention
that a caller could do something malicious by passing in an “evil”
string to be evaluated.
I don’t want to be responsible for encouraging non-vigilance toward
things like this… but if val is a string, wouldn’t eval’ing val
just result in the string, not a further evaluation of the string?
a = “puts ‘hi’”
eval “b = a”
b is now “puts ‘hi’”, but ‘hi’ doesn’t get puts’d.
(Or is there another, more evil scenario I’m not thinking of?)
I was thinking of something like
set_global_variable(name,666)
where name is given a value like ‘1 + someprog; $foo’ which would
effectively result in:
I don’t want to be responsible for encouraging non-vigilance toward
things like this… but if val is a string, wouldn’t eval’ing val
just result in the string, not a further evaluation of the string?
a = “puts ‘hi’”
eval “b = a”
b is now “puts ‘hi’”, but ‘hi’ doesn’t get puts’d.
(Or is there another, more evil scenario I’m not thinking of?)
I was thinking of something like
set_global_variable(name,666)
where name is given a value like ‘1 + someprog; $foo’ which would
effectively result in:
eval(“$1 + someprog; $foo = 666”)
I realized this (that you meant name, not val) about halfway between
my office and class