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.
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
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With