KannanR
KannanR

Reputation: 448

How to store ruby blocks in db and use them?

Basically I want to store a Ruby Block into DB and use them.

One could ask why - reason being, i want my users to be able to post / upload a block code - which could be executed to fetch a desired result for their problem on the data we might have.

Upvotes: 5

Views: 260

Answers (2)

Miguel Prz
Miguel Prz

Reputation: 13792

First, store your code as a string (the ruby2ruby gem may helps you). When you need to execute this block, retrieve it from DB, and use the "eval" method

Upvotes: 1

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230386

So you don't want to store ruby blocks. You want to store code. This is easier. Just store the code as a string. And then later you can eval that string, effectively executing the code.

Now you have to solve a hard problem: how to prevent users from posting malicious code (or how to sandbox them). But that's out of scope here.

Upvotes: 4

Related Questions