Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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