Method: Pry::Command::CodeCollector#content

Defined in:
lib/pry/commands/code_collector.rb

#contentString

The content (i.e code/docs) for the selected object. If the user provided a bare code object, it returns the source. If the user provided the ‘-i` or `-o` switches, it returns the selected input/output lines joined as a string. If the user used `-d CODE_OBJECT` it returns the docs for that code object.

Returns:

  • (String)


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/pry/commands/code_collector.rb', line 60

def content
  @content ||=
    begin
      if bad_option_combination?
        raise CommandError,
              "Only one of --out, --in, --doc and CODE_OBJECT may " \
              "be specified."
      end

      content = if opts.present?(:o)
                  pry_output_content
                elsif opts.present?(:i)
                  pry_input_content
                elsif opts.present?(:d)
                  code_object_doc
                else
                  code_object_source_or_file
                end

      restrict_to_lines(content, line_range)
    end
end