Skip to content

Instantly share code, notes, and snippets.

@nickhoffman
Last active December 15, 2015 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickhoffman/5241431 to your computer and use it in GitHub Desktop.
Save nickhoffman/5241431 to your computer and use it in GitHub Desktop.
Put each of these in ~/.irbrc
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
# Configure the prompt.
#
# This changes it from
# 1.9.3p327 :001 >
# to
# >>
IRB.conf[:PROMPT_MODE] = :SIMPLE
# 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