Last active
December 15, 2015 09:49
-
-
Save nickhoffman/5241431 to your computer and use it in GitHub Desktop.
Put each of these in ~/.irbrc
This file contains hidden or 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
if defined? Rails | |
# Customize the IRB prompt. | |
short_env = case Rails.env | |
when 'development' | |
'dev' | |
when 'production' | |
'prod' | |
else | |
Rails.env | |
end | |
# :PROMPT_I Normal prompt | |
# :PROMPT_S Prompt when continuing a string | |
# :PROMPT_C Prompt when continuing a statement | |
# :PROMPT_N Prompt when indenting code | |
# :RETURN String that prefixes output of a statement. This is passed to Kernel#printf . | |
IRB.conf[:PROMPT] ||= {} | |
IRB.conf[:PROMPT][:RAILS] = { | |
:PROMPT_I => "#{Rails.application.class.parent_name} #{short_env} > ", | |
:PROMPT_S => "#{Rails.application.class.parent_name} #{short_env} %l> ", | |
:PROMPT_C => "#{Rails.application.class.parent_name} #{short_env} > ", | |
:PROMPT_N => "#{Rails.application.class.parent_name} #{short_env} .. ", | |
:RETURN => "=> %s\n", | |
} | |
IRB.conf[:PROMPT_MODE] = :RAILS | |
end |
This file contains hidden or 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
# Configure the prompt. | |
# | |
# This changes it from | |
# 1.9.3p327 :001 > | |
# to | |
# >> | |
IRB.conf[:PROMPT_MODE] = :SIMPLE |
This file contains hidden or 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
# Easily print methods local to an object's class. E.g. | |
# p = Product.first | |
# p.local_methods | |
# p.methods_matching /price/ | |
# | |
class Object | |
def local_methods | |
(methods - Object.instance_methods).sort | |
end | |
def methods_matching(pattern) | |
methods.select {|m| m.to_s.match pattern}.sort | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment