Skip to content

Instantly share code, notes, and snippets.

@codenamev

codenamev/.pryrc Secret

Forked from 2called-chaos/.pryrc
Last active Sep 29, 2021
Embed
What would you like to do?
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", 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