From 219efec879bcac72d3f422c347d70525980df7ea Mon Sep 17 00:00:00 2001 From: Lee Jarvis Date: Sun, 21 Aug 2016 14:50:59 +0100 Subject: Handle bad constant names in Slop.option_defined? Closes #198 --- lib/slop.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') 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: -- cgit v1.2.1