summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLee Jarvis <leejarvis@fastmail.com>2016-08-21 14:50:59 +0100
committerLee Jarvis <leejarvis@fastmail.com>2016-08-21 14:50:59 +0100
commit219efec879bcac72d3f422c347d70525980df7ea (patch)
treed6bcb355d5fa63c29fe36047256cc0e13c026a57 /lib
parentf6552e8ada471452100f1ce13913fdcc8032a7e0 (diff)
downloadslop-219efec879bcac72d3f422c347d70525980df7ea.tar.gz
Handle bad constant names in Slop.option_defined?
Closes #198
Diffstat (limited to 'lib')
-rw-r--r--lib/slop.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/slop.rb b/lib/slop.rb
index 9526097..45edb7f 100644
--- a/lib/slop.rb
+++ b/lib/slop.rb
@@ -31,6 +31,10 @@ module Slop
# Returns true if an option is defined.
def self.option_defined?(name)
const_defined?(string_to_option(name.to_s))
+ rescue NameError
+ # If a NameError is raised, it wasn't a valid constant name,
+ # and thus couldn't have been defined.
+ false
end
# Example: