Class: Pry::CInternals::ShowSourceWithCInternals

Inherits:
Pry::Command::ShowSource
  • Object
show all
Defined in:
lib/pry-doc/pry_ext/show_source_with_c_internals.rb

Instance Method Summary collapse

Instance Method Details

#options(opt) ⇒ Object



5
6
7
8
# File 'lib/pry-doc/pry_ext/show_source_with_c_internals.rb', line 5

def options(opt)
  super(opt)
  opt.on :c, "c-source", "Show source of a C identifier in MRI (rather than Ruby method of same name)"
end

#processObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pry-doc/pry_ext/show_source_with_c_internals.rb', line 26

def process
  if opts.present?(:c) && !pry_instance.config.skip_cruby_source
    show_c_source
    return
  else
    super
  end
rescue Pry::CommandError
  raise if pry_instance.config.skip_cruby_source
  show_c_source
end

#show_c_sourceObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pry-doc/pry_ext/show_source_with_c_internals.rb', line 10

def show_c_source
  if opts.present?(:all)
    result, file = CodeFetcher.new(line_number_style: line_number_style)
                     .fetch_all_definitions(obj_name)
  else
    result, file = CodeFetcher.new(line_number_style: line_number_style)
                     .fetch_first_definition(obj_name)
  end
  if result
    set_file_and_dir_locals(file)
    pry_instance.pager.page result
  else
    raise Pry::CommandError, no_definition_message
  end
end