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 8836337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:28:23+00:00 2026-06-14T09:28:23+00:00

Our application uses a number of environments so we can experiment with settings without

  • 0

Our application uses a number of environments so we can experiment with settings without breaking things. In a typical controller action, I have something like this:

def some_action    
  ...
  if @foo.development_mode == 'Production'           
    @settings = SomeHelper::Production.lan(bar)
  elsif @foo.development_mode == 'Beta'
    @settings = SomeHelper::Beta.lan(nas)
  elsif @foo.development_mode == 'Experimental'
    @settings = SomeHelper::Experimental.lan(nas)
  end
  ...
 end

Since we have dozens of these, I figured I could try and dry things up with something like this:

 @settings = "SomeHelper::#{@foo.development_mode}.lan(bar)"

Which obviously doesn’t work – I just get:

 "NasHelper::Production.lan(bar)"

How can I reduce this down or do I have to stick with what I’ve got??

  • 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-06-14T09:28:24+00:00Added an answer on June 14, 2026 at 9:28 am

    If your concern is that you’re ending up with a String rather than the object, you can use String.constantize (Rails only, with standard Ruby you’d have to implement this; it uses Object.const_get(String))

    Another option would be .const_get (e.g. Object.const_get(x) where x is your string), you it doesn’t, on its own, nest correctly, so you would have to split at “::”, etc.

    Also, there’s the option of using eval to evaluate the String.
    But note: eval should be used with great care (it’s powerful), or not at all.

    Edit:

    This means that instead of:

     @settings = "SomeHelper::#{@foo.development_mode}.lan(bar)"
    

    You could run:

     @settings = "SomeHelper::#{@foo.development_mode}".constantize.lan(bar)
    

    Useful Sources:

    http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-constantize

    http://www.ruby-forum.com/topic/183112

    http://blog.grayproductions.net/articles/eval_isnt_quite_pure_evil

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

Sidebar

Related Questions

Our application is a Java-GWT application that uses Guice-Persist and Guice-Servlet extensively. We have
We have a Spring application that uses Apache DBCP for connection pooling. Our app
We have an application that uses NHibernate to connect to our database on SQL
I have a large WPF application that uses a large number of styles, brushes,
Our application uses SQL Server Reporting Services and allows users to add custom filters
Our application uses Hibernate with Sql Server 2005. Being a DBA, I am not
Our application uses a SQL Server back-end with many stored procedures. Recently, while trying
We just came across a weird bug in our application that uses the asp.net
I'm trying to set up a test environment for our application that uses X.509
After a couple of months of using our application (which internally uses Jackrabbit 1.6.4

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.