Files
dotfiles/ruby/dot-pryrc
2024-02-17 19:50:05 -05:00

44 lines
1.4 KiB
Plaintext

# frozen_string_literal: true
# Locate the gem directory for the current Ruby version and add the awesome_print directory to load path
version_path_prefix = RbConfig::CONFIG['prefix']
base_version = File.basename(version_path_prefix).tap { |basename| basename[-1] = '0' }
gems_path = File.join(version_path_prefix, 'lib', 'ruby', 'gems', base_version, 'gems')
ap_gem_dir_name = Dir.new(gems_path).children.detect { |file| file.start_with? 'awesome_print' }
if ap_gem_dir_name.nil?
puts 'Could not find AwesonePrint gem in this environment'
else
$LOAD_PATH << File.join(gems_path, ap_gem_dir_name, 'lib')
require 'awesome_print'
Pry.print = proc { |output, value| output.puts value.ai({ limit: true }) }
puts 'AwesomePrint available in this session'
end
Pry.config.editor = proc { |file, line| "nvim +'#{line}|norm! zt' file" }
# Pry::Commands.create_command 'benchmark' do
# description <<~DESCRIPTION
# Benchmark a block of code. The block is executed 100 times and the average
# time is displayed. The result of the block is also returned.
#
# Usage: benchmark do
# # code to benchmark
# end
# DESCRIPTION
#
# banner <<~BANNER
# Usage: benchmark do
# # code to benchmark
# end
# BANNER
#
# command_options takes_block: true
#
# def process
# start = Time.now
# command_block
# output.puts "Time elapsed #{Time.now - start} seconds"
# end
# end