Search code examples
rubyblock

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.


Solution

  • 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.