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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:03:32+00:00 2026-06-16T10:03:32+00:00

I have a command line utility written in Ruby using GLI framework. I would

  • 0

I have a command line utility written in Ruby using GLI framework. I would like to have configuration for my command line utility in my home directory, using Ruby itself as DSL to handle it (similar to Gemfile or Rakefile).

I have in class ConfigData in folder lib/myapp. The class looks like following way:

class ConfigData
  @@data = {}

  class ConfigItem
    def initialize
      @data = {}
    end
    def missing_method(name, *args)
      @data[name] = args[0]
    end
  end

  def self.add(section)
    item = ConfigItem.new()
    yield item
    @@data[section]=item
  end

end

Now, what I would like to have, is the config file, preferrably with name Myappfile, in current working folder, with the following content

add('section1') do |i|
  i.param1 'Some data'
  i.param2 'More data'
end

When this code was included between class and end of ConfigData, it worked fine. But now I would like to have it placed in the working folder, where I start the application.

I tried require(‘./Myappfile’) between class and end of ConfigData, but it doesn’t work for me. I tried to read the source codes of rake, but it is not very much clear to me.

Any hint how this can be solved?

  • 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-16T10:03:33+00:00Added an answer on June 16, 2026 at 10:03 am

    To evaluate code within the context of an instance, which is what you want to do, you need the instance_eval() method. Never, ever, use normal eval. Ever. Anyway, here’s how you’d load your fingi file and get the data:

    config = ConfigData.new
    config.instance_eval(File.read("Myconfig"))
    #Access configuration data here from the config object
    

    That simple. After you’ve loaded the object in that way, you can access values of the object.

    WARNING: This is not very secure. This is actually a gaping security hole. Here’s the secure version:

    f = Fiber.new {str = File.read("Myconfig"); $SAFE = 4; config = ConfigData.new; config.instance_eval(str); Fiber.yield config}
    confdata = f.resume
    #Access configuration data here from confdata.
    

    This executes the external code in a (sort of) sandbox, so that it can’t do anything dastardly.


    Also, why don’t you just use a YAML config? Unless configuration needs to run code like pwd or access RUBY_VERSION, YAML is much simpler and more secure, in addition to being more failproof.

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

Sidebar

Related Questions

I have some command-line ruby scripts for things like pre-processing text files before uploading
I have a small command line utility project that I'm using Maven to manage.
I wrote a command line utility using Zend Framework to do some nightly reporting.
I have created a Command Line Utility C++ tool in XCode using Objective-C. I
I have a command-line utility written in C#, which updates some records in the
I'm writing a command-line utility using Argparse and have added a bunch of sub_parsers
I have command line utility written in ANSI C on a Mac with a
I have a command line utility from a third party (it's big and written
I have a program which runs an external, command line utility and reads the
I have a command line tool written in c# (that i have the source

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.