From 3884013aee59ca615b440e0ef3a3520f92821cd8 Mon Sep 17 00:00:00 2001 From: Sam Westerman Date: Tue, 25 Nov 2025 17:35:11 -0800 Subject: [PATCH 1/2] Remove `const_set` and instead use explicit assignments --- lib/optparse.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/optparse.rb b/lib/optparse.rb index e0b0ff0..cdf9010 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -2314,42 +2314,42 @@ def message # Raises when ambiguously completable string is encountered. # class AmbiguousOption < ParseError - const_set(:Reason, 'ambiguous option') + Reason = 'ambiguous option' end # # Raises when there is an argument for a switch which takes no argument. # class NeedlessArgument < ParseError - const_set(:Reason, 'needless argument') + Reason = 'needless argument' end # # Raises when a switch with mandatory argument has no argument. # class MissingArgument < ParseError - const_set(:Reason, 'missing argument') + Reason = 'missing argument' end # # Raises when switch is undefined. # class InvalidOption < ParseError - const_set(:Reason, 'invalid option') + Reason = 'invalid option' end # # Raises when the given argument does not match required format. # class InvalidArgument < ParseError - const_set(:Reason, 'invalid argument') + Reason = 'invalid argument' end # # Raises when the given argument word can't be completed uniquely. # class AmbiguousArgument < InvalidArgument - const_set(:Reason, 'ambiguous argument') + Reason = 'ambiguous argument' end # @@ -2448,9 +2448,9 @@ def initialize(*args) # :nodoc: # and DecimalNumeric. See Acceptable argument classes (in source code). # module Acceptables - const_set(:DecimalInteger, OptionParser::DecimalInteger) - const_set(:OctalInteger, OptionParser::OctalInteger) - const_set(:DecimalNumeric, OptionParser::DecimalNumeric) + DecimalInteger = OptionParser::DecimalInteger + OctalInteger = OptionParser::OctalInteger + DecimalNumeric = OptionParser::DecimalNumeric end end From 68d87edc7a1213707be26a771ad17d994e171409 Mon Sep 17 00:00:00 2001 From: Sam Westerman Date: Wed, 26 Nov 2025 16:27:37 +0000 Subject: [PATCH 2/2] Update optparse.rb Co-authored-by: Nobuyoshi Nakada --- lib/optparse.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/optparse.rb b/lib/optparse.rb index cdf9010..aae73c8 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -2314,42 +2314,42 @@ def message # Raises when ambiguously completable string is encountered. # class AmbiguousOption < ParseError - Reason = 'ambiguous option' + Reason = 'ambiguous option' # :nodoc: end # # Raises when there is an argument for a switch which takes no argument. # class NeedlessArgument < ParseError - Reason = 'needless argument' + Reason = 'needless argument' # :nodoc: end # # Raises when a switch with mandatory argument has no argument. # class MissingArgument < ParseError - Reason = 'missing argument' + Reason = 'missing argument' # :nodoc: end # # Raises when switch is undefined. # class InvalidOption < ParseError - Reason = 'invalid option' + Reason = 'invalid option' # :nodoc: end # # Raises when the given argument does not match required format. # class InvalidArgument < ParseError - Reason = 'invalid argument' + Reason = 'invalid argument' # :nodoc: end # # Raises when the given argument word can't be completed uniquely. # class AmbiguousArgument < InvalidArgument - Reason = 'ambiguous argument' + Reason = 'ambiguous argument' # :nodoc: end # @@ -2448,9 +2448,11 @@ def initialize(*args) # :nodoc: # and DecimalNumeric. See Acceptable argument classes (in source code). # module Acceptables + # :stopdoc: DecimalInteger = OptionParser::DecimalInteger OctalInteger = OptionParser::OctalInteger DecimalNumeric = OptionParser::DecimalNumeric + # :startdoc: end end