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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:17:55+00:00 2026-05-30T08:17:55+00:00

In my ruby code , I try to put all the output messages in

  • 0

In my ruby code , I try to put all the output messages in one file for translation purposes, in case the client want to change the return messages it will be organized in one file.

lets assume that I have the config file with name messages.rb at root, I include it with my main.rb ruby process something like :

require “#{ROOT_PATH}/config/messages.rb”

The file will contain something like :

class Messages  
  MSG = {
    :msg1      => "Account successfully created", 
    :msg2      => "Hello" 
  }
end

Now when I call msg1 lets say in main.rb I do something like :

puts Messages::MSG[:msg2]

But as you can see it is not convient it to use it this way specially that in most of te cases I will need to include some data something like

puts Messages::MSG[:msg2] + @username

I’m sure there is some sort of dynamic conf file or other way to do it right and would appreciate it if you can provide me with the best way to do so and with the best performance .

Thanks

  • 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-30T08:17:56+00:00Added an answer on May 30, 2026 at 8:17 am

    How about having Proc objects rather than just a String?

    module Messages  
      MSG = {
        msg1: ->{"Account successfully created."},
        msg2: ->name{"Hello, #{name}. How are you doing?"}
        msg3: ->name, age{"Hello, #{name}. You are #{age} now, congrats"}
      }
    end
    

    Then you can call it like

    puts Messages::MSG[:msg1].call()  
    puts Messages::MSG[:msg2].call(@username)
    puts Messages::MSG[:msg3].call(@username, @userage)
    

    Or if you want all the messages to take the same argument(s), then just have vacuously quantified variables:

    module Messages  
      MSG = {
        msg1: ->name, age{"Account successfully created."},
        msg2: ->name, age{"Hello, #{name}. How are you doing?"} 
        msg3: ->name, age{"Hello, #{name}. You are #{age} now, congrats"}
      }
    end
    

    Then you can call it like

    puts Messages::MSG[:msg1].call(@username, @userage)
    puts Messages::MSG[:msg2].call(@username, @userage)
    puts Messages::MSG[:msg3].call(@username, @userage)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I'm writing some ruby code and I want to use the standard Date
I have some C++ Win32 code that I want to call from Ruby. But
I had seen a interesting course of Ruby on the Code School ( Try
I just have a problem with a ruby script I just want to change
When I try to do this ( real code ): fh = File.new(a file
I have some Ruby code which takes dates on the command line in the
Consider the following ruby code test.rb: begin puts thisFunctionDoesNotExist x = 1+1 rescue Exception
Here's some Ruby code: puts %x{ pstree #{$$} } # never forks puts %x{
Given the Ruby code line = first_name=mickey;last_name=mouse;country=usa record = Hash[*line.split(/=|;/)] I understand everything in
I've written some Ruby code to inspect ZIP-files as part of an internal company

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.