1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

Added AwesomePrint.irb! and AwesomePrint.pry! convenience methods

This commit is contained in:
Mike Dvorkin 2012-09-06 18:37:51 -07:00
parent 5463de12e9
commit 10efa1d60a
2 changed files with 25 additions and 18 deletions

View file

@ -232,31 +232,15 @@ Supported color names:
To use awesome_print as default formatter in irb and Rails console add the following
code to your ~/.irbrc file:
require "rubygems"
require "awesome_print"
unless IRB.version.include?('DietRB')
IRB::Irb.class_eval do
def output_value
ap @context.last_value
end
end
else # MacRuby
IRB.formatter = Class.new(IRB::Formatter) do
def inspect_object(object)
object.ai
end
end.new
end
AwesomePrint.irb!
### PRY integration ###
If you miss awesome_print's way of formatting output, here's how you can use it in place
of the formatting which comes with pry. Add the following code to your ~/.pryrc:
require "rubygems"
require "awesome_print"
Pry.print = proc { |output, value| output.puts value.ai }
AwesomePrint.pry!
### Logger Convenience Method ###
awesome_print adds the 'ap' method to the Logger and ActiveSupport::BufferedLogger classes

View file

@ -22,6 +22,29 @@ module AwesomePrint
def rails_console?
console? && !!(defined?(Rails::Console) || ENV["RAILS_ENV"])
end
def irb!
return unless defined?(IRB)
unless IRB.version.include?("DietRB")
IRB::Irb.class_eval do
def output_value
ap @context.last_value
end
end
else # MacRuby
IRB.formatter = Class.new(IRB::Formatter) do
def inspect_object(object)
object.ai
end
end.new
end
end
def pry!
if defined?(Pry)
Pry.print = proc { |output, value| output.puts value.ai }
end
end
end
class Inspector