From d21d7185834c624f805cb34b3df36b236f11b8eb Mon Sep 17 00:00:00 2001 From: Ben Bowers Date: Fri, 3 May 2024 13:14:39 -0400 Subject: [PATCH] replacing regexp with String#start_with? --- lib/optimist.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/optimist.rb b/lib/optimist.rb index 67695a9..ca310e6 100644 --- a/lib/optimist.rb +++ b/lib/optimist.rb @@ -252,7 +252,7 @@ def educate_on_error ## Otherwise, we raise an error that the partially given option was ambiguous. def perform_inexact_match(arg, partial_match) # :nodoc: return @long[partial_match] if @long.has_key?(partial_match) - partially_matched_keys = @long.keys.grep(/^#{partial_match}/) + partially_matched_keys = @long.keys.select { |opt| opt.start_with?(partial_match) } case partially_matched_keys.size when 0 ; nil when 1 ; @long[partially_matched_keys.first] @@ -331,7 +331,7 @@ def parse(cmdline = ARGV) else raise CommandlineError, "invalid argument syntax: '#{arg}'" end - if arg =~ /--no-/ # explicitly invalidate --no-no- arguments + if arg.start_with?("--no-") # explicitly invalidate --no-no- arguments sym = nil ## Support inexact matching of long-arguments like perl's Getopt::Long elsif !sym && !@settings[:exact_match] && arg.match(/^--(\S+)$/) @@ -532,7 +532,7 @@ def each_arg(args) until i >= args.length return remains += args[i..-1] if @stop_words.member? args[i] case args[i] - when /^--$/ # arg terminator + when "--" # arg terminator return remains += args[(i + 1)..-1] when /^--(\S+?)=(.*)$/ # long argument with equals num_params_taken = yield "--#{$1}", [$2] @@ -617,7 +617,7 @@ def resolve_default_short_options! opts = @specs[name] next if type != :opt || opts.short - c = opts.long.split(//).find { |d| d !~ INVALID_SHORT_ARG_REGEX && !@short.member?(d) } + c = opts.long.chars.find { |d| d !~ INVALID_SHORT_ARG_REGEX && !@short.member?(d) } if c # found a character to use opts.short = c @short[c] = name @@ -856,7 +856,7 @@ def initialize end def flag? ; true ; end def parse(_paramlist, neg_given) - return(self.name.to_s =~ /^no_/ ? neg_given : !neg_given) + return(self.name.to_s.start_with("^no_") ? neg_given : !neg_given) end end