module Commander::UI::AskForClass
def method_missing(method_name, *arguments, &block)
def method_missing(method_name, *arguments, &block) if method_name.to_s =~ /^ask_for_(.*)/ if arguments.count != 1 fail ArgumentError, "wrong number of arguments (given #{arguments.count}, expected 1)" end prompt = arguments.first requested_class = Regexp.last_match[1] # All Classes that respond to #parse # Ignore constants that trigger deprecation warnings available_classes = (Object.constants - DEPRECATED_CONSTANTS).map do |const| Object.const_get(const) rescue RuntimeError # Rescue errors in Ruby 3 for SortedSet: # The `SortedSet` class has been extracted from the `set` library. end.compact.select do |const| const.instance_of?(Class) && const.respond_to?(:parse) end klass = available_classes.find { |k| k.to_s.downcase == requested_class } if klass HighLine.default_instance.ask(prompt, klass) else super end else super end end