Class: Pry::WrappedModule::Candidate
- Extended by:
- Forwardable
- Includes:
- CodeObject::Helpers, Helpers::DocumentationHelpers
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/wrapped_module/candidate.rb
Overview
This class represents a single candidate for a module/class definition. It provides access to the source, documentation, line and file for a monkeypatch (reopening) of a class/module.
Constant Summary
Constants included from Helpers::DocumentationHelpers
Helpers::DocumentationHelpers::YARD_TAGS
Instance Attribute Summary collapse
-
#file ⇒ String
(also: #source_file)
readonly
The file where the module definition is located.
-
#line ⇒ Fixnum
(also: #source_line)
readonly
The line where the module definition is located.
Instance Method Summary collapse
-
#doc ⇒ String
The documentation for the candidate.
-
#initialize(wrapper, rank) ⇒ Candidate
constructor
A new instance of Candidate.
-
#source ⇒ String
The source for the candidate, i.e the complete module/class definition.
-
#source_location ⇒ Array?
A ‘[String, Fixnum]` pair representing the source location (file and line) for the candidate or `nil` if no source location found.
Methods included from Forwardable
Methods included from CodeObject::Helpers
#c_method?, #c_module?, #command?, #module_with_yard_docs?, #real_method_object?
Methods included from Helpers::DocumentationHelpers
get_comment_content, process_comment_markup, process_rdoc, process_yardoc, process_yardoc_tag, strip_comments_from_c_code, strip_leading_whitespace
Constructor Details
#initialize(wrapper, rank) ⇒ Candidate
Returns a new instance of Candidate.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/wrapped_module/candidate.rb', line 38 def initialize(wrapper, rank) @wrapper = wrapper if number_of_candidates <= 0 raise CommandError, "Cannot find a definition for #{name} module!" end if rank > (number_of_candidates - 1) raise CommandError, "No such module candidate. Allowed candidates range is " \ "from 0 to #{number_of_candidates - 1}" end @source = @source_location = nil @rank = rank @file, @line = source_location end |
Instance Attribute Details
#file ⇒ String (readonly) Also known as: source_file
Returns The file where the module definition is located.
14 15 16 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/wrapped_module/candidate.rb', line 14 def file @file end |
#line ⇒ Fixnum (readonly) Also known as: source_line
Returns The line where the module definition is located.
18 19 20 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/wrapped_module/candidate.rb', line 18 def line @line end |
Instance Method Details
#doc ⇒ String
Returns The documentation for the candidate.
70 71 72 73 74 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/wrapped_module/candidate.rb', line 70 def doc return nil if file.nil? @doc ||= get_comment_content(Pry::Code.from_file(file).comment_describing(line)) end |
#source ⇒ String
Returns The source for the candidate, i.e the complete module/class definition.
59 60 61 62 63 64 65 66 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/wrapped_module/candidate.rb', line 59 def source return nil if file.nil? return @source if @source @source ||= strip_leading_whitespace( Pry::Code.from_file(file).expression_at(line, number_of_lines_in_first_chunk) ) end |
#source_location ⇒ Array?
Returns A ‘[String, Fixnum]` pair representing the source location (file and line) for the candidate or `nil` if no source location found.
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/wrapped_module/candidate.rb', line 79 def source_location return @source_location if @source_location file, line = first_method_source_location return nil unless file.is_a?(String) @source_location = [file, first_line_of_module_definition(file, line)] rescue Pry::RescuableException nil end |