string command

R

ruby talk

------=_Part_110430_22092251.1136953085135
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hello,
Is there a way to make ruby interpret a string as a set of command?
for example
action=3D"p this is test one"
action.command
action=3D"for i in 1..4
p this is test two
end"
action.command

and have the out put be
this is test one
this is test two
this is test two
this is test two
this is test two


I am working with TK gui and want to create a general popup menu fuction,
but i need to set the commands for differnt menus.

------=_Part_110430_22092251.1136953085135--
 
D

David Vallner

ruby said:
Hello,
Is there a way to make ruby interpret a string as a set of command?
for example
action="p this is test one"
action.command
action="for i in 1..4
p this is test two
end"
action.command

and have the out put be
this is test one
this is test two
this is test two
this is test two
this is test two


I am working with TK gui and want to create a general popup menu fuction,
but i need to set the commands for differnt menus.
eval the strings. Mind you, the "p this is test one" is bad code, you
can only eval syntactically valid Ruby. Also, eval has certain security
implications, especially with user-supplied strings forming part of the
eval-ed code. If you want to make general popup menus, I'd personally
use a proc instead of a string to specify the action, because you might
run into passing around bindings with your strings real soon for
non-trivial event handlers, and jagged blades and boggy swamps await
that way. Or perhaps not.

David Vallner
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top