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"] 3 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: 9 10>> require 'pp' 11=> true 12 13>> pp months 14["January", 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"] 3 4>> pp months 5["January", 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.