Skip to content

Instantly share code, notes, and snippets.

@sbuller
Created May 17, 2012 21:23
Show Gist options
  • Save sbuller/2721656 to your computer and use it in GitHub Desktop.
Save sbuller/2721656 to your computer and use it in GitHub Desktop.
def format(line, binding)
pattern = /[[:alpha:]\$_][[:alnum:]_]*/
line.gsub(pattern) {|match| replace(match,binding) }
end
def replace(match, binding)
reserved_words = "alias,and,BEGIN,begin,break,case,class,def,defined?,do,else,elsif,END,end,ensure,false,for,if,in,module,next,nil,not,or,redo,rescue,retry,return,self,super,then,true,undef,unless,until,when,while,yield".split(",")
if reserved_words.rindex match
return match
end
type = eval("defined? #{match}", binding)
case type
when "local-variable"
return eval(match, binding) || match
else
return match
end
end
p = proc { |event, file, line_number, id, binding, classname|
if event == "line"
printf "%s:%-3d ", file, line_number
line = IO.readlines(file)[line_number - 1].chomp
printf "%-10s | %s\n", line, format(line, binding)
end
}
set_trace_func p
def test
x = 7
puts x
end
x = 3
puts x
test
set_trace_func nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment