configuration file for a standalone ruby script

ruby, ruby-on-rails

Solution

First, you can run an independent script that writes to a YAML configuration file:

require "yaml"
File.write("path_to_yaml_file", [arg1, arg2].to_yaml)

Then, read it within your app:

require "yaml"
arg1, arg2 = YAML.load_file("path_to_yaml")
# use arg1, arg2
...

Problem

I have a ruby script that runs on a linux server. Its not using rails or anything. Its basically a commandline ruby script that can be passed arguments like this: `./ruby_script.rb arg1 arg2` How can I abstract away the arguments into a configuration file such as a yaml file or something? Can you provide an example of how this can be done? Thank you in advance.

Original source