ruby picture

RCR 215: Object#pretty

Submitted by ahoward (Fri Feb 13 13:02:53 UTC 2004)

Abstract

make pretty_printing more available and easier to use

Problem

Proposal

creation of Object#pretty method which is analogous to Object#inspect, only returning result of 'pp' instead of the result from 'p'

Analysis

simply add a method

Implementation

class Object
  def pretty s = ''<br>
    autoload :PP, 'pp'<br>
    PP::pp self, s<br>
    s<br>
  end<br>
end
ruby picture
Comments Current voting

This isn't needed, really.

  s = [].methods
  require 'pp'
  s.methods - s
  s.pretty_print_inspect


Since PP.pp(obj, out) returns out,

  s = ''
  PP::pp very_large_hash, s
  raise ArgumentError, s

can be described as:

  raise ArgumentError, PP::pp(very_large_hash, '')

Note that pretty_print_inspect doesn't solve the problem because it is designed to use as inspect using pretty_print.


Strongly opposed 1
Opposed 5
Neutral 0
In favor 0
Strongly advocate 0
ruby picture

This RCR supersedes RCR 214.

If you have registered at RCRchive, you may now sign in below. If you have not registered, you may sign up for a username and password. Registering enables you to submit new RCRs, and vote and leave comments on existing RCRs.
Your username:
Your password:

ruby picture

Powered by .