Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6475563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:43:10+00:00 2026-05-25T06:43:10+00:00

I want to allow evaluation of code in a shell-like app. At a press

  • 0

I want to allow evaluation of code in a shell-like app. At a press of a button, the code will be evaluated and a result will be showed to the user. I want to make it so that if he evaluates code again, everything defined in old evaluation will no longer exist. For example, imagine this is eval #1:

puts "Hello world"
user_variable1  = 10
$USER_VARIABLE2 = 20

I want that on eval #2, the values of user_variable1 and $USER_VARIABLE2 not to exist. This is why I’m thinking of using some kind of context on each run. However, I don’t know where to look for more info.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:43:10+00:00Added an answer on May 25, 2026 at 6:43 am

    You could just run another (or the same script) in another process using some way of executing the commands. Something like

    system('myscript.rb')
    

    or

    `myscript.rb`
    

    This will ensure that any variables are cleared, however, the environment variables will of course be the same. Since ruby 1.9 you can reset them too, though. Like so:

    system('myscript.rb', :unsetenv_others => true)
    

    If you want something very close to the eval() function, you could create an eval.rb, that will just evaluate the first parameter and then define an evalExt function:

    eval.rb:

    eval(ARGV[0])
    

    And then in your other script:
    def evalExt(script)
    system(“eval.rb \”#{script}\””, :unsetenv_others => true)
    end

    evalExt('puts "test"')
    evalExt('puts "test1"')
    

    In case of JRuby you should be able to invoke another ruby engine as easily, by calling Java code from JRuby and then using the ScriptEngineManager as described on Wikipedia:

    require 'java'
    
    mgr = ScriptEngineManager.new();
    rbEngine = mgr.getEngineByExtension("rb");
    
    def evalExt(script)
       rbEngine.eval(script);
    end
    

    Maybe you will have to ensure to reset the script context or bindings (see this article).

    All that said, maybe the easiest solution would be to just ensure that no global variables are set, then you do not have to seperate contexts at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want allow the user to customize their web pages on my ASP.NET MVC
I want to allow the user to click a start point and then click
I want to allow the user to use lowercase or uppercase letters giving the
I want to allow special charecters in URL my htaccess code is <IfModule mod_rewrite.c>
I want to allow the user to download a voice file when he clicks
I want to allow a user to enter a list of persons in a
If I want allow user to add some formating, but I need prevent css
I want to allow users to make their own Python mods for my game,
I want to allow users to upload avatar-type images in a variety of formats
I want to allow an Excel report to be viewed embedded in a WebPage...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.