Given a Hash mapping a class’ methods to method
types (returned by display_class_method_list),
this method allows the user to choose one of the methods.
# File lib/rdoc/ri/display.rb, line 128
def get_class_method_choice(method_map)
if CAN_USE_READLINE
# prepare abbreviations for tab completion
abbreviations = method_map.keys.abbrev
Readline.completion_proc = proc do |string|
abbreviations.values.uniq.grep(/^#{string}/)
end
end
@formatter.raw_print_line "\nEnter the method name you want.\n"
@formatter.raw_print_line "Class methods can be preceeded by '::' and instance methods by '#'.\n"
if CAN_USE_READLINE
@formatter.raw_print_line "You can use tab to autocomplete.\n"
@formatter.raw_print_line "Enter a blank line to exit.\n"
choice_string = Readline.readline(">> ").strip
else
@formatter.raw_print_line "Enter a blank line to exit.\n"
@formatter.raw_print_line ">> "
choice_string = $stdin.gets.strip
end
if choice_string == ''
return nil
else
class_or_instance = method_map[choice_string]
if class_or_instance
# If the user's choice is not preceeded by a '::' or a '#', figure
# out whether they want a class or an instance method and decorate
# the choice appropriately.
if(choice_string =~ /^[a-zA-Z]/)
if(class_or_instance == :class)
choice_string = "::#{choice_string}"
else
choice_string = "##{choice_string}"
end
end
return choice_string
else
@formatter.raw_print_line "No method matched '#{choice_string}'.\n"
return nil
end
end
end