Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object_id option not operating as expected #89

Open
MadBomber opened this issue Dec 23, 2022 · 1 comment
Open

object_id option not operating as expected #89

MadBomber opened this issue Dec 23, 2022 · 1 comment

Comments

@MadBomber
Copy link

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
#Clinician:0x000000012838e2c0 {

}
=> nil

irb(main):004:0> ap c, object_id: false

but it is still here ....

#Clinician:0x000000012838e2c0 {

}
=> nil

irb(main):005:0> ap c, object_id: true

but it is still here ...

#Clinician:0x000000012838e2c0 {

}
=> nil

irb(main):006:0> defined? AmazingPrint
=> "constant"

irb(main):007:0> defined? AwesomePrint
=> nil

The same thing happens if I use Awesome.

@HarlemSquirrel
Copy link
Member

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

str = object.send(options[:class_name]).to_s
return str unless options[:object_id]

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.

# Catch all method to format an arbitrary object.
#------------------------------------------------------------------------------
def awesome_self(object, type)
if @options[:raw] && object.instance_variables.any?
awesome_object(object)
elsif (hash = convert_to_hash(object))
awesome_hash(hash)
else
awesome_simple(object.inspect.to_s, type, @inspector)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants