Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

amazing_print

> 编程语言
Open source

Pretty print your Ruby objects with style -- in full color and with proper indentation

853 stars0 likes6 views
WebsiteGitHub

About

Pretty print your Ruby objects with style -- in full color and with proper indentation

Amazing Print

RubyGems RubyGems |

| AmazingPrint is a fork of AwesomePrint, which became stale, and should be used in its place to avoid conflicts. It 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.

Supported Versions

  • Ruby >= 3.2
  • Rails >= 6.1

Installation

# Installing as Ruby gem
$ gem install amazing_print

# Cloning the repository
$ git clone git://github.com/amazing-print/amazing_print.git

Usage

ruby
require "amazing_print"
ap object, options = {}

Default options:

…

Supported color names:

ruby
:gray, :red, :green, :yellow, :blue, :purple, :cyan, :white
:grayish, :redish, :greenish, :yellowish, :blueish, :purpleish, :cyanish, :whiteish

Use Object#ai to return an ASCII encoded string:

ruby
irb> "awesome print".ai
=> "\e[0;33m\"awesome print\"\e[0m"

Examples

…

Example (Rails console)

…

IRB integration

To use amazing_print as the default formatter in irb and the Rails console, add the following code to your ~/.irbrc file:

ruby
require "amazing_print"
AmazingPrint.irb!
AmazingPrint.rdbg! # Enables integration with ruby debug

PRY integration

If you miss amazing_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:

ruby
require "amazing_print"
AmazingPrint.pry!

Logger Convenience Method

amazing_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 it on a per call basis with:

logger.ap object, :warn
# or
logger.ap object, level: :warn

You can also pass additional options (providing nil or leaving off level will log at the default level):

logger.ap object, { level: :info, sort_keys: true }

ActionView Convenience Method

amazing_print adds the ap method to the ActionView::Base class making it available within Rails templates. For example:

   # ERB
!= ap @accounts.first       # HAML

With other web frameworks (for example in Sinatra templates) you can explicitly request HTML formatting:

 true %>

Colorizing Strings

Use methods such as .red to set string color:

ruby
irb> puts AmazingPrint::Colors.red("red text")
red text # (it's red)

Setting Custom Defaults

You can set your own default options by creating an aprc file in your $XDG_CONFIG_HOME directory (which defaults to ~/.config if undefined). Within that file assign your defaults to AmazingPrint.defaults. For example:

ruby
# ~/.config/aprc file.
AmazingPrint.defaults = {
  :indent => -2,
  :color => {
    :hash  => :whiteish,
    :class => :white
  }
}

The previous ~/.aprc location is still supported as a fallback.

Versioning

AmazingPrint follows the Semantic Versioning standard.

Contributing

See CONTRIBUTING.md for information.

License

Copyright (c) 2010-2016 Michael Dvorkin and contributors

http://www.dvorkin.net

%w(mike dvorkin.net) * "@" || "twitter.com/mid"

Released under the MIT license. See LICENSE file for details.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyhacktoberfest

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言