Skip to content

Instantly share code, notes, and snippets.

@2called-chaos
Created September 26, 2021 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 2called-chaos/2994346579729acb17d3b03b1802e6d3 to your computer and use it in GitHub Desktop.
Save 2called-chaos/2994346579729acb17d3b03b1802e6d3 to your computer and use it in GitHub Desktop.
My pryrc file
Pry.config.editor = "subl"
Pry.hooks.add_hook(:before_eval, "runtime_start") do |output, pry|
pry.instance_variable_set(:"@x_runtime_start", Time.now)
end
Pry.hooks.add_hook(:after_eval, "runtime_end") do |output, pry|
pry.instance_variable_set(:"@x_runtime_end", Time.now)
end
Pry.config.print = proc do |output, value, _pry_|
rts = _pry_.instance_variable_get(:"@x_runtime_start")
rte = _pry_.instance_variable_get(:"@x_runtime_end")
_pry_.instance_variable_set(:"@x_runtime_start", false)
_pry_.instance_variable_set(:"@x_runtime_end", false)
if rts && rte
rt = (rte - rts)
rtms = (rt * 1000.0).round
rtus = (rt * 1000.0 * 1000.0).round
rtf = rtms.zero? ? "#{rtus}µs" : "#{rtms}ms"
end
_pry_.pager.open do |pager|
pager.print "\e[30m#{rtf}\e[0m #{_pry_.config.output_prefix}"
Pry::ColorPrinter.pp(value, pager, output.width)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment