Ruby 2.5 requires pp by default

Prathamesh Sonpatki

By Prathamesh Sonpatki

on December 20, 2017

This blog is part of our  Ruby 2.5 series.

Ruby 2.5.0-preview1 was recently released.

Ruby allows pretty printing of objects using pp method.

Before Ruby 2.5, we had to require PP explicitly before using it. Even the official documentation states that "All examples assume you have loaded the PP class with require 'pp'".

1>> months = %w(January February March)
2=> ["January", "February", "March"]
4>> pp months
5NoMethodError: undefined method `pp' for main:Object
6Did you mean?  p
7	from (irb):5
8	from /Users/prathamesh/.rbenv/versions/2.4.1/bin/irb:11:
10>> require 'pp'
11=> true
13>> pp months
15 "February",
16 "March"]
17=> ["January", "February", "March"]

In Ruby 2.5, we don't need to require pp. It gets required by default. We can use it directly.

1>> months = %w(January February March)
2=> ["January", "February", "March"]
4>> pp months
6 "February",
7 "March"]
8=> ["January", "February", "March"]

This feature was added after Ruby 2.5.0 preview 1 was released, so it's not present in the preview. It's present in Ruby trunk.

Stay up to date with our blogs. Sign up for our newsletter.

We write about Ruby on Rails, ReactJS, React Native, remote work,open source, engineering & design.