amazing-print / amazing_print

Pretty print your Ruby objects with style -- in full color and with proper indentation
MIT License
768 stars 31 forks source link

object_id option not operating as expected #89

Open MadBomber opened 1 year ago

MadBomber commented 1 year ago

The object_id option is not doing what I expect so either there is a software problem or a wetware problem.

Software Versions: Amazing ... 1.4.0 Ruby ...... 3.0.1p64 Rails ..... 6.1.3

Running the Rails Console/Irb ....

irb(main):002:0> c = Clinician.first Clinician Load (1.1ms) SELECT "clinicians".* FROM "clinicians" ORDER BY "clinicians"."id" ASC LIMIT $1 [["LIMIT", 1]] =>

<Clinician:0x000000012838e2c0

irb(main):003:0> ap c # I want to get rid of this object ID vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv # { } => nil irb(main):004:0> ap c, object_id: false # but it is still here .... # { } => nil irb(main):005:0> ap c, object_id: true # but it is still here ... # { } => nil irb(main):006:0> defined? AmazingPrint => "constant" irb(main):007:0> defined? AwesomePrint => nil The same thing happens if I use Awesome.
HarlemSquirrel commented 1 year ago

Hey there! I think there's some confusion about how this currently works and it probably could use some improvement.

This is only used by the object formatter https://github.com/amazing-print/amazing_print/blob/8c0ae339e309b27badf45ec92bd5fb1176ed5c31/lib/amazing_print/formatters/object_formatter.rb#L65-L66

This object formatter is only used when a specialized formatter doesn't match the object, raw: true is set, and the object has at least one instance variable. https://github.com/amazing-print/amazing_print/blob/8c0ae339e309b27badf45ec92bd5fb1176ed5c31/lib/amazing_print/formatter.rb#L43-L51

require 'amazing_print'

thread = Thread.new {}
ap thread, raw: true, object_id: false
#<Thread:0x00007fd2e7111f18 (irb):3 dead>
nil

require 'ostruct'
obj = OpenStruct.new(pizza: "place")
ap obj, raw: true, object_id: false
#<OpenStruct
  attr_reader :table = {
    pizza: "place"
  }
>
nil