0

I understand that one can use something like object.inspect to view an object's state in the console (or to whichever output one is using), but does there exist a built-in method or a gem which provides a method to print out the object's state in an easy-to-read fashion?

Example:

> some_blog_post_object.beautiful_inspect
=> "title:    'Some Amazing Title'
    subtitle: 'Hopefully I'm not down-voted for n00b-ness'
    image:    'some_image.jpg'
           .
           .
           .
   "

Or something along these lines.

solidstatejake
  • 202
  • 3
  • 9
  • Perhaps not quite what you want, but you can try the built-in pretty-printer: `require 'pp'` ... `pp some_blog_post_object` – Chris Schmich Jun 12 '19 at 01:27
  • 1
    If `pp` doesn't work for you, then there may be a gem. Try Google searching on "ruby gem pretty print objects". I just tried that and saw a few promising links. – lurker Jun 12 '19 at 01:32
  • 2
    Possible duplicate of [Ruby: How to make IRB print structure for Arrays and Hashes](https://stackoverflow.com/questions/703049/ruby-how-to-make-irb-print-structure-for-arrays-and-hashes) – rosalynnas Jun 12 '19 at 01:52
  • I didn't know it was called "pretty printing". Great. – solidstatejake Jun 12 '19 at 02:13

1 Answers1

2

https://github.com/awesome-print/awesome_print can be a good fit. I recommend to combine it with pry.

ksevelyar
  • 332
  • 3
  • 6