Skip to content

Instantly share code, notes, and snippets.

@rubysolo
Forked from banister/empty
Created June 17, 2011 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubysolo/1031868 to your computer and use it in GitHub Desktop.
Save rubysolo/1031868 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment