def run_some_script
ruby_code = Mytable.ruby_code
eval("ruby_code")
end
Depending on the ultimate source of that code - if you don't trust the
string completely, you might want to do:
def run_some_script
ruby_code = Mytable.ruby_code
Thread.new do
$SAFE = 3
eval(ruby_code)
end.join
end
It will stop things like "system('del filename')" from being eval'd.
(I think that's the right way to go about it... I don't have the need to
do unsafe evals that often).
···
-----Original Message-----
From: Fernand Galiana [mailto:fernand@dim.com]
Sent: Tuesday, 11 October 2005 4:07 PM
To: ruby-talk ML
Subject: Executing ruby code withing a ruby appHi,
I have some ruby code stached away in a database table. I
would like to run this code within my ruby application.
How can I do it ?For example say I have the following method:
def run_some_script
ruby_code = Mytable.ruby_code # Where Mytable is an
ActiveRecord object that references a db table which contains
some ruby script# Now I want to run the ruby script that is in the db
table and return the result of the execution
endThank you all for the help...
#####################################################################################
This email has been scanned by MailMarshal, an email content filter.
#####################################################################################