Skip to content

Instantly share code, notes, and snippets.

@codenamev

codenamev/.pryrc Secret

Forked from 2called-chaos/.pryrc
Last active December 2, 2021 13:20
Show Gist options
  • Save codenamev/d8b8ee0cb73e88bec969fe67aec6cbb8 to your computer and use it in GitHub Desktop.
Save codenamev/d8b8ee0cb73e88bec969fe67aec6cbb8 to your computer and use it in GitHub Desktop.
My pryrc file
Pry.hooks.add_hook(:before_eval, "runtime_start") do |output, pry|
pry.instance_variable_set(:"@x_runtime_start", Process.clock_gettime(Process::CLOCK_MONOTONIC))
end
Pry.hooks.add_hook(:after_eval, "runtime_end") do |output, pry|
pry.instance_variable_set(:"@x_runtime_end", Process.clock_gettime(Process::CLOCK_MONOTONIC))
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