From 0c8fe93fcc57b4aae6bc245262fd4b905649b44a Mon Sep 17 00:00:00 2001 From: Whyme Lyu Date: Sun, 9 Oct 2022 01:29:11 +0800 Subject: [PATCH 1/3] OptionParser#load learns .load(into: Hash) --- lib/optparse.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/optparse.rb b/lib/optparse.rb index 9dad2e4..6f7106e 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -1903,10 +1903,10 @@ def candidate(word) # directory ~/.options, then the basename with '.options' suffix # under XDG and Haiku standard places. # - def load(filename = nil) + def load(filename = nil, into: nil) unless filename basename = File.basename($0, '.*') - return true if load(File.expand_path(basename, '~/.options')) rescue nil + return true if load(File.expand_path(basename, '~/.options'), into: into) rescue nil basename << ".options" return [ # XDG @@ -1918,11 +1918,11 @@ def load(filename = nil) '~/config/settings', ].any? {|dir| next if !dir or dir.empty? - load(File.expand_path(basename, dir)) rescue nil + load(File.expand_path(basename, dir), into: into) rescue nil } end begin - parse(*IO.readlines(filename).each {|s| s.chomp!}) + parse(*IO.readlines(filename).each {|s| s.chomp!}, into: into) true rescue Errno::ENOENT, Errno::ENOTDIR false From cab528ee896a7bc00d55fd6eca091bbadc791d93 Mon Sep 17 00:00:00 2001 From: Whyme Lyu Date: Sun, 9 Oct 2022 03:08:32 +0800 Subject: [PATCH 2/3] Docs on .load(into: Hash-like) --- lib/optparse.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/optparse.rb b/lib/optparse.rb index 6f7106e..f99acef 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -1903,6 +1903,9 @@ def candidate(word) # 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 + # def load(filename = nil, into: nil) unless filename basename = File.basename($0, '.*') From 0101cb204c8fe2691b05055f2efc7a0f29a68945 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 29 Oct 2022 22:43:18 +0900 Subject: [PATCH 3/3] Update lib/optparse.rb --- lib/optparse.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/optparse.rb b/lib/optparse.rb index f99acef..238fa1e 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -1904,7 +1904,7 @@ def candidate(word) # under XDG and Haiku standard places. # # The optional +into+ keyword argument works exactly like that accepted in - # method #parse + # method #parse. # def load(filename = nil, into: nil) unless filename