Class: Pry::Command::ShowSource

Inherits:
Command::ShowInfo
  • Object
show all
Defined in:
lib/pry/commands/show_source.rb

Instance Method Summary collapse

Instance Method Details

#content_for(code_object) ⇒ Object

The source for code_object prepared for display.



44
45
46
47
48
49
50
# File 'lib/pry/commands/show_source.rb', line 44

def content_for(code_object)
  code = Code.new(
    code_object.source || [],
    start_line_for(code_object)
  )
  code.with_line_numbers(use_line_numbers?).highlighted
end

#options(opt) ⇒ Object



28
29
30
31
32
# File 'lib/pry/commands/show_source.rb', line 28

def options(opt)
  opt.on :e, :eval, "evaluate the command's argument as a ruby " \
                    "expression and show the class its return value"
  super(opt)
end

#process ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/pry/commands/show_source.rb', line 34

def process
  if opts.present?(:e)
    obj = target.eval(args.first)
    self.args = Array.new(1) { obj.is_a?(Module) ? obj.name : obj.class.name }
  end

  super
end