Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions lib/optparse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ def candidate(key, icase = false, pat = nil, &_)
Completion.candidate(key, icase, pat, &method(:each))
end

public
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary; nothing previously set private or protected

def complete(key, icase = false, pat = nil)
candidates = candidate(key, icase, pat, &method(:each)).sort_by {|k, v, kn| kn.size}
if candidates.size == 1
Expand Down Expand Up @@ -562,7 +561,7 @@ def initialize(pattern = nil, conv = nil,
# Parses +arg+ and returns rest of +arg+ and matched portion to the
# argument pattern. Yields when the pattern doesn't match substring.
#
def parse_arg(arg) # :nodoc:
private def parse_arg(arg) # :nodoc:
pattern or return nil, [arg]
unless m = pattern.match(arg)
yield(InvalidArgument, arg)
Expand All @@ -580,14 +579,13 @@ def parse_arg(arg) # :nodoc:
yield(InvalidArgument, arg) # didn't match whole arg
return arg[s.length..-1], m
end
private :parse_arg

#
# Parses argument, converts and returns +arg+, +block+ and result of
# conversion. Yields at semi-error condition instead of raising an
# exception.
#
def conv_arg(arg, val = []) # :nodoc:
private def conv_arg(arg, val = []) # :nodoc:
v, = *val
if conv
val = conv.call(*val)
Expand All @@ -599,7 +597,6 @@ def conv_arg(arg, val = []) # :nodoc:
end
return arg, block, val
end
private :conv_arg

#
# Produces the summary text. Each line of the summary is yielded to the
Expand Down Expand Up @@ -883,14 +880,13 @@ def reject(t)
# +lopts+:: Long style option list.
# +nlopts+:: Negated long style options list.
#
def update(sw, sopts, lopts, nsw = nil, nlopts = nil) # :nodoc:
private def update(sw, sopts, lopts, nsw = nil, nlopts = nil) # :nodoc:
sopts.each {|o| @short[o] = sw} if sopts
lopts.each {|o| @long[o] = sw} if lopts
nlopts.each {|o| @long[o] = nsw} if nsw and nlopts
used = @short.invert.update(@long.invert)
@list.delete_if {|o| Switch === o and !used[o]}
end
private :update

#
# Inserts +switch+ at the head of the list, and associates short, long
Expand Down Expand Up @@ -1459,14 +1455,13 @@ def to_a; summarize("#{banner}".split(/^/)) end
# +prv+:: Previously specified argument.
# +msg+:: Exception message.
#
def notwice(obj, prv, msg) # :nodoc:
private def notwice(obj, prv, msg) # :nodoc:
unless !prv or prv == obj
raise(ArgumentError, "argument #{msg} given twice: #{obj}",
ParseError.filter_backtrace(caller(2)))
end
obj
end
private :notwice

SPLAT_PROC = proc {|*a| a.length <= 1 ? a.first : a} # :nodoc:

Expand Down Expand Up @@ -1733,7 +1728,7 @@ def order!(argv = default_argv, into: nil, **keywords, &nonopt)
parse_in_order(argv, setter, **keywords, &nonopt)
end

def parse_in_order(argv = default_argv, setter = nil, exact: require_exact, **, &nonopt) # :nodoc:
private def parse_in_order(argv = default_argv, setter = nil, exact: require_exact, **, &nonopt) # :nodoc:
opt, arg, val, rest = nil
nonopt ||= proc {|a| throw :terminate, a}
argv.unshift(arg) if arg = catch(:terminate) {
Expand Down Expand Up @@ -1824,10 +1819,9 @@ def parse_in_order(argv = default_argv, setter = nil, exact: require_exact, **,

argv
end
private :parse_in_order

# Calls callback with _val_.
def callback!(cb, max_arity, *args) # :nodoc:
private def callback!(cb, max_arity, *args) # :nodoc:
args.compact!

if (size = args.size) < max_arity and cb.to_proc.lambda?
Expand All @@ -1837,7 +1831,6 @@ def callback!(cb, max_arity, *args) # :nodoc:
end
cb.call(*args)
end
private :callback!

#
# Parses command line arguments +argv+ in permutation mode and returns
Expand Down Expand Up @@ -1951,24 +1944,22 @@ def self.getopts(*args, symbolize_names: false)
# Traverses @stack, sending each element method +id+ with +args+ and
# +block+.
#
def visit(id, *args, &block) # :nodoc:
private def visit(id, *args, &block) # :nodoc:
@stack.reverse_each do |el|
el.__send__(id, *args, &block)
end
nil
end
private :visit

#
# Searches +key+ in @stack for +id+ hash and returns or yields the result.
#
def search(id, key) # :nodoc:
private def search(id, key) # :nodoc:
block_given = block_given?
visit(:search, id, key) do |k|
return block_given ? yield(k) : k
end
end
private :search

#
# Completes shortened long style option switch and returns pair of
Expand All @@ -1979,7 +1970,7 @@ def search(id, key) # :nodoc:
# +icase+:: Search case insensitive if true.
# +pat+:: Optional pattern for completion.
#
def complete(typ, opt, icase = false, *pat) # :nodoc:
private def complete(typ, opt, icase = false, *pat) # :nodoc:
if pat.empty?
search(typ, opt) {|sw| return [sw, opt]} # exact match or...
end
Expand All @@ -1989,7 +1980,6 @@ def complete(typ, opt, icase = false, *pat) # :nodoc:
exc = ambiguous ? AmbiguousOption : InvalidOption
raise exc.new(opt, additional: proc {|o| additional_message(typ, o)})
end
private :complete

#
# Returns additional info.
Expand Down