public
Created — forked from banister/empty

  • Download Gist
empty
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
pry(main):4> blame_for(Pry.instance_method(:repl)).display
John Mair def repl(target=TOPLEVEL_BINDING)
John Mair target = Pry.binding_for(target)
John Mair target_self = target.eval('self')
John Mair
John Mair repl_prologue(target)
Mon ouïe
John Mair # cannot rely on nesting.level as
John Mair # nesting.level changes with new sessions
John Mair nesting_level = nesting.size
John Mair
John Mair break_data = catch(:breakout) do
John Mair nesting.push [nesting.size, target_self, self]
John Mair loop do
John Mair rep(target)
John Mair end
John Mair end
John Mair
John Mair return_value = repl_epilogue(target, nesting_level, break_data)
Lee Jarvis return_value || target_self
John Mair end
=> nil
pry(main):4> show-method blame_for
 
From: (pry) @ line 108:
Number of lines: 11
 
def blame_for(meth)
@repo ||= Grit::Repo.new(".")
start_line = meth.source_location.last
num_lines = meth.source.lines.count
size = num_lines
l = start_line
obj = []
authors = @repo.blame(meth.source_location.first).lines.select { |v| v.lineno >= l && v.lineno <= l + size }.map { |v| v.commit.author.output(Time.new).split(/</).first.strip }
meth.source.lines.zip(authors) { |line, author| obj << ("#{author}".ljust(10) + line) }
obj.join
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.