@@ -1855,7 +1855,7 @@ def permute(*argv, **keywords)
1855
1855
#
1856
1856
def permute! ( argv = default_argv , **keywords )
1857
1857
nonopts = [ ]
1858
- order! ( argv , **keywords , & nonopts . method ( :<< ) )
1858
+ order! ( argv , **keywords ) { | nonopt | nonopts << nonopt }
1859
1859
argv [ 0 , 0 ] = nonopts
1860
1860
argv
1861
1861
end
@@ -1908,13 +1908,16 @@ def getopts(*args, symbolize_names: false, **keywords)
1908
1908
single_options , *long_options = *args
1909
1909
1910
1910
result = { }
1911
+ setter = ( symbolize_names ?
1912
+ -> ( name , val ) { result [ name . to_sym ] = val }
1913
+ : -> ( name , val ) { result [ name ] = val } )
1911
1914
1912
1915
single_options . scan ( /(.)(:)?/ ) do |opt , val |
1913
1916
if val
1914
- result [ opt ] = nil
1917
+ setter [ opt , nil ]
1915
1918
define ( "-#{ opt } VAL" )
1916
1919
else
1917
- result [ opt ] = false
1920
+ setter [ opt , false ]
1918
1921
define ( "-#{ opt } " )
1919
1922
end
1920
1923
end if single_options
@@ -1923,16 +1926,16 @@ def getopts(*args, symbolize_names: false, **keywords)
1923
1926
arg , desc = arg . split ( ';' , 2 )
1924
1927
opt , val = arg . split ( ':' , 2 )
1925
1928
if val
1926
- result [ opt ] = val . empty? ? nil : val
1929
+ setter [ opt , ( val unless val . empty? ) ]
1927
1930
define ( "--#{ opt } =#{ result [ opt ] || "VAL" } " , *[ desc ] . compact )
1928
1931
else
1929
- result [ opt ] = false
1932
+ setter [ opt , false ]
1930
1933
define ( "--#{ opt } " , *[ desc ] . compact )
1931
1934
end
1932
1935
end
1933
1936
1934
- parse_in_order ( argv , result . method ( :[]= ) , **keywords )
1935
- symbolize_names ? result . transform_keys ( & :to_sym ) : result
1937
+ parse_in_order ( argv , setter , **keywords )
1938
+ result
1936
1939
end
1937
1940
1938
1941
#
@@ -1982,7 +1985,7 @@ def complete(typ, opt, icase = false, *pat) # :nodoc:
1982
1985
visit ( :complete , typ , opt , icase , *pat ) { |o , *sw | return sw }
1983
1986
}
1984
1987
exc = ambiguous ? AmbiguousOption : InvalidOption
1985
- raise exc . new ( opt , additional : self . method ( : additional_message) . curry [ typ ] )
1988
+ raise exc . new ( opt , additional : proc { | o | additional_message ( typ , o ) } )
1986
1989
end
1987
1990
private :complete
1988
1991
@@ -2273,9 +2276,10 @@ def recover(argv)
2273
2276
argv
2274
2277
end
2275
2278
2279
+ DIR = File . join ( __dir__ , '' )
2276
2280
def self . filter_backtrace ( array )
2277
2281
unless $DEBUG
2278
- array . delete_if ( & %r" \A #{ Regexp . quote ( __FILE__ ) } :"o . method ( :=~ ) )
2282
+ array . delete_if { | bt | bt . start_with? ( DIR ) }
2279
2283
end
2280
2284
array
2281
2285
end
0 commit comments