https://github.com/awesome-print/awesome_print
Pretty print your Ruby objects with style -- in full color and with proper indentation
https://github.com/awesome-print/awesome_print
Keywords from Contributors
activerecord activejob mvc rubygems crash-reporting rspec rubocop ruby-gem static-code-analysis mongodb-driver
Last synced: about 23 hours ago
JSON representation
Repository metadata
Pretty print your Ruby objects with style -- in full color and with proper indentation
- Host: GitHub
- URL: https://github.com/awesome-print/awesome_print
- Owner: awesome-print
- License: mit
- Created: 2010-04-03T04:45:43.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2024-08-15T20:03:46.000Z (over 1 year ago)
- Last Synced: 2025-12-08T10:29:29.234Z (9 days ago)
- Language: Ruby
- Homepage: http://github.com/michaeldv/awesome_print
- Size: 812 KB
- Stars: 4,086
- Watchers: 41
- Forks: 452
- Open Issues: 108
- Releases: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
README.md
Awesome Print
Awesome Print is a Ruby library that pretty prints Ruby objects in full color
exposing their internal structure with proper indentation. Rails ActiveRecord
objects and usage within Rails templates are supported via included mixins.
NOTE: awesome_print v1.9.0 may not work on Ruby versions 2.4 or older or Rails versions 4.2 or older.
The upcoming awesome_print v2.0 will require Ruby v1.9.3 or later and Rails v3.0 or later.
Installation
# Installing as Ruby gem
$ gem install awesome_print
# Cloning the repository
$ git clone git://github.com/awesome-print/awesome_print.git
Usage
require "awesome_print"
ap object, options = {}
Default options:
indent: 4, # Number of spaces for indenting.
index: true, # Display array indices.
html: false, # Use ANSI color codes rather than HTML.
multiline: true, # Display in multiple lines.
plain: false, # Use colors.
raw: false, # Do not recursively format instance variables.
sort_keys: false, # Do not sort hash keys.
sort_vars: true, # Sort instance variables.
limit: false, # Limit arrays & hashes. Accepts bool or int.
ruby19_syntax: false, # Use Ruby 1.9 hash syntax in output.
class_name: :class, # Method called to report the instance class name. (e.g. :to_s)
object_id: true, # Show object id.
color: {
args: :pale,
array: :white,
bigdecimal: :blue,
class: :yellow,
date: :greenish,
falseclass: :red,
integer: :blue,
float: :blue,
hash: :pale,
keyword: :cyan,
method: :purpleish,
nilclass: :red,
rational: :blue,
string: :yellowish,
struct: :pale,
symbol: :cyanish,
time: :greenish,
trueclass: :green,
variable: :cyanish
}
Supported color names:
:gray, :red, :green, :yellow, :blue, :purple, :cyan, :white
:black, :redish, :greenish, :yellowish, :blueish, :purpleish, :cyanish, :pale
Use Object#ai to return an ASCII encoded string:
irb> "awesome print".ai
=> "\e[0;33m\"awesome print\"\e[0m"
Examples
Array
$ cat > 1.rb
require "awesome_print"
data = [ false, 42, %w(forty two), { :now => Time.now, :class => Time.now.class, :distance => 42e42 } ]
ap data
^D
$ ruby 1.rb
[
[0] false,
[1] 42,
[2] [
[0] "forty",
[1] "two"
],
[3] {
:class => Time < Object,
:now => Fri Apr 02 19:55:53 -0700 2010,
:distance => 4.2e+43
}
]
Hash
$ cat > 2.rb
require "awesome_print"
data = { :now => Time.now, :class => Time.now.class, :distance => 42e42 }
ap data, :indent => -2 # <-- Left align hash keys.
^D
$ ruby 2.rb
{
:class => Time < Object,
:now => Fri Apr 02 19:55:53 -0700 2010,
:distance => 4.2e+43
}
Nested array
$ cat > 3.rb
require "awesome_print"
data = [ false, 42, %w(forty two) ]
data << data # <-- Nested array.
ap data, :multiline => false
^D
$ ruby 3.rb
[ false, 42, [ "forty", "two" ], [...] ]
Class methods
$ cat > 4.rb
require "awesome_print"
class Hello
def self.world(x, y, z = nil, &blk)
end
end
ap Hello.methods - Class.methods
^D
$ ruby 4.rb
[
[0] world(x, y, *z, &blk) Hello
]
Object methods
$ cat > 5.rb
require "awesome_print"
ap (''.methods - Object.methods).grep(/!/)
^D
$ ruby 5.rb
[
[ 0] capitalize!() String
[ 1] chomp!(*arg1) String
[ 2] chop!() String
[ 3] delete!(*arg1) String
[ 4] downcase!() String
[ 5] encode!(*arg1) String
[ 6] gsub!(*arg1) String
[ 7] lstrip!() String
[ 8] next!() String
[ 9] reverse!() String
[10] rstrip!() String
[11] slice!(*arg1) String
[12] squeeze!(*arg1) String
[13] strip!() String
[14] sub!(*arg1) String
[15] succ!() String
[16] swapcase!() String
[17] tr!(arg1, arg2) String
[18] tr_s!(arg1, arg2) String
[19] upcase!() String
]
Compare output to value
$ cat > 6.rb
require "awesome_print"
ap 42 == ap(42)
^D
$ ruby 6.rb
42
true
Array with default output limit
$ cat > 7.rb
require "awesome_print"
some_array = (1..1000).to_a
ap some_array, :limit => true
^D
$ ruby 7.rb
[
[ 0] 1,
[ 1] 2,
[ 2] 3,
[ 3] .. [996],
[997] 998,
[998] 999,
[999] 1000
]
Array with specific output limit
$ cat > 8.rb
require "awesome_print"
some_array = (1..1000).to_a
ap some_array, :limit => 5
^D
$ ruby 8.rb
[
[ 0] 1,
[ 1] 2,
[ 2] .. [997],
[998] 999,
[999] 1000
]
Rails console
$ rails console
rails> require "awesome_print"
rails> ap Account.limit(2).all
[
[0] #<Account:0x1033220b8> {
:id => 1,
:user_id => 5,
:assigned_to => 7,
:name => "Hayes-DuBuque",
:access => "Public",
:website => "http://www.hayesdubuque.com",
:toll_free_phone => "1-800-932-6571",
:phone => "(111)549-5002",
:fax => "(349)415-2266",
:deleted_at => nil,
:created_at => Sat, 06 Mar 2010 09:46:10 UTC +00:00,
:updated_at => Sat, 06 Mar 2010 16:33:10 UTC +00:00,
:email => "info@hayesdubuque.com",
:background_info => nil
},
[1] #<Account:0x103321ff0> {
:id => 2,
:user_id => 4,
:assigned_to => 4,
:name => "Ziemann-Streich",
:access => "Public",
:website => "http://www.ziemannstreich.com",
:toll_free_phone => "1-800-871-0619",
:phone => "(042)056-1534",
:fax => "(106)017-8792",
:deleted_at => nil,
:created_at => Tue, 09 Feb 2010 13:32:10 UTC +00:00,
:updated_at => Tue, 09 Feb 2010 20:05:01 UTC +00:00,
:email => "info@ziemannstreich.com",
:background_info => nil
}
]
rails> ap Account
class Account < ActiveRecord::Base {
:id => :integer,
:user_id => :integer,
:assigned_to => :integer,
:name => :string,
:access => :string,
:website => :string,
:toll_free_phone => :string,
:phone => :string,
:fax => :string,
:deleted_at => :datetime,
:created_at => :datetime,
:updated_at => :datetime,
:email => :string,
:background_info => :string
}
rails>
IRB integration
To use awesome_print as default formatter in irb and Rails console add the following
code to your ~/.irbrc file:
require "awesome_print"
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
or your project's ./.pryrc:
require "awesome_print"
AwesomePrint.pry!
Logger Convenience Method
awesome_print adds the 'ap' method to the Logger and ActiveSupport::BufferedLogger classes
letting you call:
logger.ap object
By default, this logs at the :debug level. You can override that globally with:
:log_level => :info
in the custom defaults (see below). You can also override on a per call basis with:
logger.ap object, :warn
ActionView Convenience Method
awesome_print adds the 'ap' method to the ActionView::Base class making it available
within Rails templates. For example:
<%= ap @accounts.first %> # ERB
!= ap @accounts.first # HAML
With other web frameworks (ex: in Sinatra templates) you can explicitly request HTML
formatting:
<%= ap @accounts.first, :html => true %>
String Convenience Methods
Use methods such as .red to set string color:
irb> puts "red text".red
red text # (it's red)
Setting Custom Defaults
You can set your own default options by creating .aprc file in your home
directory. Within that file assign your defaults to AwesomePrint.defaults.
For example:
# ~/.aprc file.
AwesomePrint.defaults = {
:indent => -2,
:color => {
:hash => :pale,
:class => :white
}
}
Versioning
AwesomePrint follows the Semantic Versioning standard.
Contributing
See CONTRIBUTING.md for information.
License
Copyright (c) 2010-2016 Michael Dvorkin and contributors
%w(mike dvorkin.net) * "@" || "twitter.com/mid"
Released under the MIT license. See LICENSE file for details.
Owner metadata
- Name: Awesome Print Ruby Gem
- Login: awesome-print
- Email:
- Kind: organization
- Description:
- Website: https://rubygems.org/gems/awesome_print
- Location:
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/19637607?v=4
- Repositories: 1
- Last ynced at: 2024-03-25T18:49:00.622Z
- Profile URL: https://github.com/awesome-print
GitHub Events
Total
- Issues event: 3
- Watch event: 35
- Issue comment event: 6
- Pull request event: 3
- Fork event: 3
Last Year
- Issues event: 3
- Watch event: 28
- Issue comment event: 5
- Pull request event: 3
- Fork event: 3
Committers metadata
Last synced: 3 days ago
Total Commits: 409
Total Committers: 71
Avg Commits per committer: 5.761
Development Distribution Score (DDS): 0.604
Commits in past year: 0
Committers in past year: 0
Avg Commits per committer in past year: 0.0
Development Distribution Score (DDS) in past year: 0.0
| Name | Commits | |
|---|---|---|
| Mike Dvorkin | m****e@d****t | 162 |
| Gerard Caulfield | g****t@c****e | 38 |
| Waldyr de Souza | w****r@g****m | 30 |
| James Cox | j****s@i****s | 25 |
| Mauro George | m****t@g****m | 23 |
| Bryan Hanks, PMP | g****b@m****m | 11 |
| Tobias Crawley | t****y@g****m | 8 |
| Andrew Horsman | m****s@g****m | 7 |
| Jonathan Davies | j****e@o****k | 7 |
| shyndman | s****n@g****m | 6 |
| fuJiin | f****n@g****m | 6 |
| Dan Weinand | d****d@g****m | 5 |
| Viktar Basharymau | 6****b@g****m | 4 |
| Tatsuya Hoshino | t****7@g****m | 4 |
| Nicolas Viennot | n****s@v****z | 3 |
| Elliot Shank | g****b@g****m | 3 |
| Dave Gynn | d****n@g****m | 3 |
| Stephan Hagemann | s****n@x****m | 3 |
| Daniel Bretoi | d****l@n****g | 2 |
| Marshall Shen | m****n@g****m | 2 |
| Aaron Heesakkers | a****s@g****m | 2 |
| Andrew O'Brien | a****w@e****m | 2 |
| George | g****e@b****m | 2 |
| Gudleik Rasch | g****k@g****m | 2 |
| Kurt Stephens | k****b@k****m | 2 |
| Nikolaj Nikolajsen | nn@p****k | 2 |
| 1z3n | 1****4@g****m | 1 |
| Adriano Mitre | a****e@g****m | 1 |
| Barry Allard | b****y@b****e | 1 |
| adamjonas | j****s@f****m | 1 |
| and 41 more... | ||
Committer domains:
- me.com: 1
- vstone.eu: 1
- florianebeling.com: 1
- rabidtech.co.nz: 1
- danlynn.org: 1
- velocis.us: 1
- grandrounds.com: 1
- member.fsf.org: 1
- dio.jp: 1
- fansnap.com: 1
- jpcutler.net: 1
- gurge.com: 1
- hechtllc.com: 1
- well.com: 1
- tryphon.org: 1
- gitter.im: 1
- mikemcquaid.com: 1
- mullistechnologies.com: 1
- kvedulv.de: 1
- buzzlabs.com: 1
- galileo.gbdev.com: 1
- mmullis-quad-1.(none): 1
- attinteractive.com: 1
- saltpepper.ru: 1
- flatironschool.com: 1
- barryallard.name: 1
- peytz.dk: 1
- kurtstephens.com: 1
- boost-media.com: 1
- econify.com: 1
- groupon.com: 1
- netwalk.org: 1
- xing.com: 1
- galumph.com: 1
- viennot.biz: 1
- obdev.co.uk: 1
- master-developer.com: 1
- imaj.es: 1
- caulfield.me: 1
- dvorkin.net: 1
Issue and Pull Request metadata
Last synced: 9 days ago
Total issues: 56
Total pull requests: 58
Average time to close issues: 11 months
Average time to close pull requests: over 1 year
Total issue authors: 55
Total pull request authors: 36
Average comments per issue: 2.66
Average comments per pull request: 1.9
Merged pull request: 15
Bot issues: 0
Bot pull requests: 0
Past year issues: 1
Past year pull requests: 6
Past year average time to close issues: about 21 hours
Past year average time to close pull requests: N/A
Past year issue authors: 1
Past year pull request authors: 2
Past year average comments per issue: 1.0
Past year average comments per pull request: 0.17
Past year merged pull request: 0
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- n-rodriguez (2)
- wedsonlima (1)
- FunnyHector (1)
- LizPrescott (1)
- MadBomber (1)
- jsvd (1)
- 5hanth (1)
- hasibduetcse (1)
- daBee (1)
- molleweide (1)
- denishaskin (1)
- goldylucks (1)
- ritec (1)
- dsfernandobond (1)
- dawncold (1)
Top Pull Request Authors
- BryanH (14)
- HarlemSquirrel (4)
- tennisvelu (4)
- jclusso (2)
- dahal (2)
- JasonnnW3000 (2)
- paulodiovani (1)
- smudge (1)
- steakknife (1)
- buugworm (1)
- febeling (1)
- amomchilov (1)
- RST-J (1)
- dweinand (1)
- gvwirth (1)
Top Issue Labels
- Feature request (4)
- Awaiting response (2)
- Needs a PR (1)
Top Pull Request Labels
- needs-work (4)
- Awaiting response (3)
- work-in-progress (2)
- Spike (2)
- ToDo (1)
- candidate-for-release (1)
- Feature request (1)
Package metadata
- Total packages: 3
-
Total downloads:
- rubygems: 536,159,473 total
- Total docker downloads: 995,914,768
- Total dependent packages: 1,840 (may contain duplicates)
- Total dependent repositories: 34,572 (may contain duplicates)
- Total versions: 58
- Total maintainers: 4
gem.coop: awesome_print
Great Ruby debugging companion: pretty print Ruby objects to visualize their structure. Supports custom object formatting via plugins
- Homepage: https://github.com/awesome-print/awesome_print
- Documentation: http://www.rubydoc.info/gems/awesome_print/
- Licenses: MIT
- Latest release: 1.9.2 (published almost 5 years ago)
- Last Synced: 2025-12-14T21:00:51.507Z (3 days ago)
- Versions: 23
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 268,076,038 Total
- Docker Downloads: 497,957,384
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.056%
- Downloads: 0.089%
- Docker downloads count: 0.134%
- Maintainers (4)
rubygems.org: awesome_print
Great Ruby debugging companion: pretty print Ruby objects to visualize their structure. Supports custom object formatting via plugins
- Homepage: https://github.com/awesome-print/awesome_print
- Documentation: http://www.rubydoc.info/gems/awesome_print/
- Licenses: MIT
- Latest release: 1.9.2 (published almost 5 years ago)
- Last Synced: 2025-12-15T04:31:12.856Z (2 days ago)
- Versions: 23
- Dependent Packages: 1,840
- Dependent Repositories: 34,572
- Downloads: 268,083,435 Total
- Docker Downloads: 497,957,384
-
Rankings:
- Dependent packages count: 0.028%
- Downloads: 0.08%
- Dependent repos count: 0.178%
- Docker downloads count: 0.258%
- Stargazers count: 0.318%
- Average: 0.354%
- Forks count: 1.263%
- Maintainers (4)
proxy.golang.org: github.com/awesome-print/awesome_print
- Homepage:
- Documentation: https://pkg.go.dev/github.com/awesome-print/awesome_print#section-documentation
- Licenses: mit
- Latest release: v1.9.2 (published almost 5 years ago)
- Last Synced: 2025-12-15T05:27:38.159Z (2 days ago)
- Versions: 12
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent packages count: 6.999%
- Average: 8.173%
- Dependent repos count: 9.346%
Dependencies
- appraisal >= 0 development
- fakefs >= 0.2.1 development
- nokogiri >= 1.11.0 development
- rspec >= 3.0.0 development
- sqlite3 >= 0 development
Score: 33.75400301433713