Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2ea626f

Browse files
5longnobu
andauthored
#load() into hash (#42)
OptionParser#load learns .load(into: Hash) Co-authored-by: Nobuyoshi Nakada <[email protected]>
1 parent fb34a1d commit 2ea626f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/optparse.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,10 +1903,13 @@ def candidate(word)
19031903
# directory ~/.options, then the basename with '.options' suffix
19041904
# under XDG and Haiku standard places.
19051905
#
1906-
def load(filename = nil)
1906+
# The optional +into+ keyword argument works exactly like that accepted in
1907+
# method #parse.
1908+
#
1909+
def load(filename = nil, into: nil)
19071910
unless filename
19081911
basename = File.basename($0, '.*')
1909-
return true if load(File.expand_path(basename, '~/.options')) rescue nil
1912+
return true if load(File.expand_path(basename, '~/.options'), into: into) rescue nil
19101913
basename << ".options"
19111914
return [
19121915
# XDG
@@ -1918,11 +1921,11 @@ def load(filename = nil)
19181921
'~/config/settings',
19191922
].any? {|dir|
19201923
next if !dir or dir.empty?
1921-
load(File.expand_path(basename, dir)) rescue nil
1924+
load(File.expand_path(basename, dir), into: into) rescue nil
19221925
}
19231926
end
19241927
begin
1925-
parse(*IO.readlines(filename).each {|s| s.chomp!})
1928+
parse(*IO.readlines(filename).each {|s| s.chomp!}, into: into)
19261929
true
19271930
rescue Errno::ENOENT, Errno::ENOTDIR
19281931
false

0 commit comments

Comments
 (0)