模組 OptionParser::Completion
關鍵字完成模組。這允許指定部分引數並根據可接受值的清單進行解析。
公開類別方法
candidate(key, icase = false, pat = nil, &block) 按一下以切換來源
# File lib/optparse.rb, line 445 def self.candidate(key, icase = false, pat = nil, &block) pat ||= Completion.regexp(key, icase) candidates = [] block.call do |k, *v| (if Regexp === k kn = "" k === key else kn = defined?(k.id2name) ? k.id2name : k pat === kn end) or next v << k if v.empty? candidates << [k, v, kn] end candidates end
regexp(key, icase) 按一下以切換來源
# File lib/optparse.rb, line 441 def self.regexp(key, icase) Regexp.new('\A' + Regexp.quote(key).gsub(/\w+\b/, '\&\w*'), icase) end
公開執行個體方法
candidate(key, icase = false, pat = nil) 按一下以切換來源
# File lib/optparse.rb, line 462 def candidate(key, icase = false, pat = nil) Completion.candidate(key, icase, pat, &method(:each)) end
complete(key, icase = false, pat = nil) { |key, *sw| ... } 按一下以切換來源
# File lib/optparse.rb, line 467 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 canon, sw, * = candidates[0] elsif candidates.size > 1 canon, sw, cn = candidates.shift candidates.each do |k, v, kn| next if sw == v if String === cn and String === kn if cn.rindex(kn, 0) canon, sw, cn = k, v, kn next elsif kn.rindex(cn, 0) next end end throw :ambiguous, key end end if canon block_given? or return key, *sw yield(key, *sw) end end
convert(opt = nil, val = nil, *) 按一下以切換來源
# File lib/optparse.rb, line 492 def convert(opt = nil, val = nil, *) val end