BigBinary Blog

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

Ruby 2.5 requires pp by default

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.

Prathamesh Sonpatki in Ruby 2.5
December 20, 2017

Subscribe to our newsletter