fix make_header bug (fix #286)

This commit is contained in:
Ryan Fitzgerald 2011-10-02 20:13:10 -07:00
parent 3a36d28342
commit ddb51d5b38
2 changed files with 18 additions and 9 deletions

View File

@ -40,13 +40,15 @@ class Pry
end
def make_header(meth, content=meth.source)
code_type = meth.source_type
num_lines = "Number of lines: #{Pry::Helpers::Text.bold(content.each_line.count.to_s)}"
case code_type
when :c
file = Pry::MethodInfo.info_for(meth).file
"\n#{Pry::Helpers::Text.bold('From:')} #{file} in Ruby Core (C Method):\n#{num_lines}\n\n"
header = "\n#{Pry::Helpers::Text.bold('From:')} #{meth.source_file} "
if meth.source_type == :c
header << "in Ruby Core (C Method):\n"
else
header << "@ line #{meth.source_line}:\n"
end
header << "Number of lines: #{Pry::Helpers::Text.bold(content.each_line.count.to_s)}\n\n"
end
def file_map

View File

@ -1,6 +1,6 @@
class Pry
class Method
include RbxMethod if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
include RbxMethod if Helpers::BaseHelpers.rbx?
class << self
# Given a string representing a method name and optionally a binding to
@ -127,7 +127,7 @@ class Pry
# `:ruby` for ordinary Ruby methods, `:c` for methods written in
# C, or `:rbx` for Rubinius core methods written in Ruby.
def source_type
if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
if Helpers::BaseHelpers.rbx?
if core? then :rbx else :ruby end
else
if source_location.nil? then :c else :ruby end
@ -137,7 +137,14 @@ class Pry
# @return [String, nil] The name of the file the method is defined in, or
# `nil` if the filename is unavailable.
def source_file
source_location.nil? ? nil : source_location.first
if source_location.nil?
if !Helpers::BaseHelpers.rbx? and source_type == :c
info = pry_doc_info
info.file if info
end
else
source_location.first
end
end
# @return [Fixnum, nil] The line of code in `source_file` which begins