Created
May 7, 2020 15:19
-
-
Save havenwood/6d3683bb2835a81f8d736f46e4c28f8f to your computer and use it in GitHub Desktop.
My ~/.irbrc irb settings file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'irb/completion' | |
require 'irb/ext/save-history' | |
IRB.conf[:SAVE_HISTORY] = 100_000_000 | |
IRB.conf[:EVAL_HISTORY] = 100_000_000 | |
IRB.conf[:PROMPT_MODE] = :SIMPLE | |
IRB.conf[:PROMPT][:SIMPLE][:PROMPT_C] = '| ' | |
# Use a proc rather than function for context to get refinements working. | |
IRB.conf[:CONTEXT_MODE] = 0 | |
require 'minitest' | |
## | |
# Provide the attr Minitest needs to use assertions a la carte. | |
# Normally this would already be provided by Minitest::Runnable, | |
# but we want to play with assertions from the top level! \o/ | |
module Minitest | |
module Assertions | |
attr_writer :assertions | |
def assertions | |
@assertions ||= 0 | |
end | |
end | |
end | |
include Minitest::Assertions | |
## | |
# A care package to provide tidbits for those moments I miss Pry the most. | |
module PryCarePackage | |
SYSTEM_CLEAR = %w[clear cls].freeze | |
DEFAULT_ARGUMENT = Object.new.freeze | |
BORING = [self, Class, Module, BasicObject, Object, Kernel, | |
Minitest::Assertions].freeze | |
def ls(object = DEFAULT_ARGUMENT) | |
subject = object == DEFAULT_ARGUMENT ? self : object | |
result = if subject.instance_of?(Class) || subject.instance_of?(Module) | |
subject_methods = subject.instance_methods(false) | |
subject_methods.empty? ? {} : {"#{subject}#" => subject_methods} | |
else | |
ancestor_methods = (subject.class.ancestors - BORING).to_h do |ancestor| | |
["#{ancestor}#", ancestor.instance_methods(false)] | |
end | |
ancestor_methods.reject { |_key, value| value.empty? } | |
end | |
class_methods = subject.public_methods(false) & subject.methods(false) | |
result['self.'] = class_methods if class_methods.any? | |
constants = subject.respond_to?(:constants) ? subject.constants : [] | |
result['Constants'] = constants if constants.any? | |
result | |
end | |
def clear | |
conf.return_format = '' | |
SYSTEM_CLEAR.reduce false do |success, command| | |
system [command, command] unless success | |
end | |
end | |
def reset | |
conf.return_format = '' | |
puts 'irb reset.' | |
exec [$PROGRAM_NAME, $PROGRAM_NAME] | |
end | |
end | |
include PryCarePackage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment