Module: Pry::DefaultCommands::ModuleIntrospectionHelpers
- Defined in:
- lib/pry/default_commands/introspection.rb
Overview
For show-doc and show-source
Instance Attribute Summary collapse
-
#module_object ⇒ Object
Returns the value of attribute module_object.
Instance Method Summary collapse
- #attempt ⇒ Object
- #method? ⇒ Boolean
- #module?(name) ⇒ Boolean
- #module_start_line(mod, candidate_rank = 0) ⇒ Object
- #process(name) ⇒ Object
- #process_alternatives ⇒ Object
- #use_line_numbers? ⇒ Boolean
Instance Attribute Details
#module_object ⇒ Object
Returns the value of attribute module_object.
8 9 10 |
# File 'lib/pry/default_commands/introspection.rb', line 8 def module_object @module_object end |
Instance Method Details
#attempt ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/pry/default_commands/introspection.rb', line 55 def attempt rank = 0 begin yield(rank) rescue Pry::CommandError raise if rank > (module_object.number_of_candidates - 1) rank += 1 retry end end |
#method? ⇒ Boolean
14 15 16 17 18 |
# File 'lib/pry/default_commands/introspection.rb', line 14 def method? !!method_object rescue CommandError false end |
#module?(name) ⇒ Boolean
10 11 12 |
# File 'lib/pry/default_commands/introspection.rb', line 10 def module?(name) self.module_object = Pry::WrappedModule.from_str(name, target) end |
#module_start_line(mod, candidate_rank = 0) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/pry/default_commands/introspection.rb', line 43 def module_start_line(mod, candidate_rank=0) if opts.present?(:'base-one') 1 else mod.candidate(candidate_rank).line end end |
#process(name) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pry/default_commands/introspection.rb', line 20 def process(name) if module?(name) code_or_doc = process_module elsif method? code_or_doc = process_method else code_or_doc = process_alternatives end render_output(code_or_doc, opts) end |
#process_alternatives ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pry/default_commands/introspection.rb', line 32 def process_alternatives if args.empty? && internal_binding?(target) mod = target_self.is_a?(Module) ? target_self : target_self.class self.module_object = Pry::WrappedModule(mod) process_module else process_method end end |
#use_line_numbers? ⇒ Boolean
51 52 53 |
# File 'lib/pry/default_commands/introspection.rb', line 51 def use_line_numbers? opts.present?(:b) || opts.present?(:l) end |