string to code?

P

Pavel Pvl

is it possible to get user input, and put that in as a code. like lets
say i ask for command and the user types types something like twice 3
which would refer to to a method twice n??
 
T

Tim Hunter

Pavel said:
is it possible to get user input, and put that in as a code. like lets
say i ask for command and the user types types something like twice 3
which would refer to to a method twice n??

Well, you can certainly use the eval method, which just executes a
string as Ruby code, but there is some risk involved. You probably
wouldn't want to allow somebody to type

system('del *.*')

for example.

Unless you're very smart and very careful (like _why:
http://tryruby.hobix.com/) you shouldn't allow the user to type in real
Ruby code.
 
P

Pavel Pvl

yes i know that, and in the actual app im not going to have that. just
for my self.

thank you very much

I love ruby
 
S

Sebastian Hungerecker

Tim said:
Well, you can certainly use the eval method, which just executes a
string as Ruby code, but there is some risk involved. You probably
wouldn't want to allow somebody to type

system('del *.*')

for example.

Why not? I mean the user wouldn't type something like this without knowing
what it means/does. So if he wants to delete all his files why not let him?

Of course it's different when the script runs on another system than the user
is on, but since the op mentioned getting input from the user via gets, I
assume this is not the case here.
 

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
474,274
Messages
2,571,366
Members
48,052
Latest member
EvaW192252

Latest Threads

Top