[前][次][番号順一覧][スレッド一覧]

ruby-changes:74288

From: Whyme <ko1@a...>
Date: Sat, 29 Oct 2022 22:46:40 +0900 (JST)
Subject: [ruby-changes:74288] 37291df91d (master): [ruby/optparse] #load() into hash

https://git.ruby-lang.org/ruby.git/commit/?id=37291df91d

From 37291df91dea2616559e64751ae6f8ed799c4310 Mon Sep 17 00:00:00 2001
From: Whyme Lyu <5longluna@g...>
Date: Sat, 29 Oct 2022 21:46:23 +0800
Subject: [ruby/optparse] #load() into hash
 (https://github.com/ruby/optparse/pull/42)

OptionParser#load learns .load(into: Hash)

https://github.com/ruby/optparse/commit/2ea626fcff

Co-authored-by: Nobuyoshi Nakada <nobu@r...>
---
 lib/optparse.rb | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/lib/optparse.rb b/lib/optparse.rb
index 9dad2e4eda..238fa1e219 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -1903,10 +1903,13 @@ XXX https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L1903
   # directory ~/.options, then the basename with '.options' suffix
   # under XDG and Haiku standard places.
   #
-  def load(filename = nil)
+  # 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, '.*')
-      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 +1921,11 @@ XXX https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L1921
         '~/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
-- 
cgit v1.2.3


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]