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

  • Home
  • SEARCH
  • 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 6962283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:38:26+00:00 2026-05-27T15:38:26+00:00

I inherited maintenance on an app that uses eval() as a way to evaluate

  • 0

I inherited maintenance on an app that uses eval() as a way to evaluate rules written in Ruby code in a rules engine. I know there are a lot of other ways to do it, but the code base so far is pretty big, and changing it to something else would be prohibitive time-wise at this point; so assume I’m stuck using eval() for the moment.

The rules as written typically call up some of the same objects from the database as each other, and the rules writer gave the variables in the rules the same names as each other. This is resulting in pages and pages of “already initialized constant” warnings in the console during development.

I’m wondering a couple things:

First, if feels like those are slowing down the execution of the program in the dev environment, and so I’m wondering if it’s a big performance hit in the production environment, specifically, having those warnings pop, not eval() itself, which I know is a hit.

Second, is there any way to “namespace” the execution of each rules so that it’s not defining its variables on the same scope as all the other evals in the request to avoid that warning popping all over the place? I know I could rewrite all the rules to use ||= syntax or to check if a name has already been defined, but there’s quite a lot of them so I’d rather do it from the code that runs the eval()‘s, if possible.

** update with example rule **
A question has a rule about when it’s to be displayed to a user. For example, if the user has stated that they live in an apartment, another question might need to be shown to ask what size the apartment building is. So the second question’s rule_text might look like:

UserLivesInApartment = Question.find_by_name "UserLivesInApartment"
UserLivesInApartment.answer_for(current_user)

The code that calls the eval ensures there’s a current_user variable in scope prior to evaluating.

  • 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-27T15:38:27+00:00Added an answer on May 27, 2026 at 3:38 pm

    uh, eval is not perhaps the most golden of standards. You could probably fire up a drb instance and run the stuff in that instead of eval, that way you would have at least some control of what is happening and not pollute your own namespace.

    http://segment7.net/projects/ruby/drb/introduction.html


    Edit: added another answer for running the code in the same process:

    I don’t know how your rule code looks, but it might be possible to wrap a module around it:

    # create a module
    module RuleEngineRun1;end
    # run code in module
    RuleEngineRun1.module_eval("class Foo;end")
    
    # get results
    #....
    
    # cleanup
    Object.send(:remove_const, :RuleEngineRun1)
    

    You can also create an anonymous module with Module.new { #block to be module eval’d } if you need to run code in parallel.


    In later rubies you can add -W0 to run your code without printing warnings, but doing so makes possible errors go unnoticed:

    $ cat foo.rb 
    FOO = :bar
    FOO = :bar
    
    $ ruby foo.rb 
    foo.rb:2: warning: already initialized constant FOO
    
    $ ruby -W0 foo.rb 
    

    You could also run your eval inside a Kernel.silence_warnings block, but might be devastating as well if you actually run into some real problems with the eval’d code, see
    Suppress Ruby warnings when running specs

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

Sidebar

Related Questions

I have inherited some code that uses the ref keyword extensively and unnecessarily. The
I inherited an Intraweb app that had a 2MB text file of memory leaks
I'm doing maintenance work on a Rails site that I inherited; it's driven by
I've inherited some code that I need to debug. It isn't working at present.
I have an app that uses several prefixes and, while not frequent, it's also
I'm doing some maintenance on a legacy webapp. The app uses a 3rd party
I've inherited a web app in need of some maintenance and all of the
I have inherited a SQL CLR project as part of a code maintenance project
I inherited a project that uses CoreData for a certain type of data storage.
We inherited some leagcy code that has a whole lot of code copy/pasted across

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.