Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
OptionParser#load
(?::String filename) -> bool
load(filename = nil, **keywords)
lib/optparse.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/lib/optparse.rb, line 2019
def load(filename = nil, **keywords)
unless filename
basename = File.basename($0, '.*')
return true if load(File.expand_path(basename, '~/.options'), **keywords) rescue nil
basename << ".options"
return [
# XDG
ENV['XDG_CONFIG_HOME'],
'~/.config',
*ENV['XDG_CONFIG_DIRS']&.split(File::PATH_SEPARATOR),
# Haiku
'~/config/settings',
].any? {|dir|
next if !dir or dir.empty?
load(File.expand_path(basename, dir), **keywords) rescue nil
}
end
begin
parse(*File.readlines(filename, chomp: true), **keywords)
true
rescue Errno::ENOENT, Errno::ENOTDIR
false
end
end
Loads options from file names as filename. Does nothing when the file is not present. Returns whether successfully loaded.
filename defaults to basename of the program without suffix in a directory ~/.options, then the basename with ‘.options’ suffix under XDG and Haiku standard places.
The optional into keyword argument works exactly like that accepted in method parse.