Method: Code.from_docs

Defined in:
lib/code.rb

.from_docs(m) ⇒ Object

Find C definition of Code



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/code.rb', line 45

def self.from_docs(m)
  if RUBY_ENGINE != "ruby"
    raise Code::NotFound, "Method source not found for non-CRuby."
  elsif !defined?(CoreDocs)
    raise Code::NotFound, 'Method source not found. Might be possible with core_docs gem'
  elsif !(method_info = CoreDocs::MethodInfo.info_for(m))
    raise Code::NotFound, 'Method source not found.'
  else
    source = method_info.source
    location = "//\n//   #{cruby_on_github(method_info.file, method_info.line)}\n//\n"
    comment = method_info.docstring ?  method_info.docstring.gsub(/^/, '// ') + "\n" : ""

    display location + comment + source, :c
  end
end