You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The reason I'm trying to use this is, I have an ActiveRecord model with a to_s instance method, and want to print out the class/model name when I print it to console or debug log. Example:
Hi @tgrushka and thanks for taking the time to open this issue.
I've not used this feature myself or even tried it since I forked the repo but I spent some time poking around today and it seems the :class_name option only works with the ObjectFormatter today which is only used when raw: true is set. Additionally, the class name option is only used when object_id: false option is set.
Here's an examaple of it working today:
require_relative'lib/amazing_print'classPersonattr_accessor:nameattr_reader:created_atdefinitialize@created_at=Time.nowendendclassWizard < Personattr_accessor:swordendperson=Wizard.newperson.name='Gandalf'person.sword='Glamdring'puts"\n Just ap"appersonputs"\n Now ap with class_name: :name"apperson,class_name: :name,object_id: false,raw: true
Here's the output I get
I'm definitely open to improving this so :class_name is used in more places.
It does make sense to me to omit the object ID when using custom class names to avoid confusion about the real class name so that part may just need clarifying in our documentation.
In both Rails 6 console and IRB, (and in the original AwesomePrint gem as well), the
class_name
option doesn't seem to have any effect.The class name seems to always be printed as the result of calling
to_s
on the object, no matter what theclass_name
option is set to.The reason I'm trying to use this is, I have an ActiveRecord model with a
to_s
instance method, and want to print out the class/model name when I print it to console or debug log. Example:I would like to be able to see the class name, like when I do:
But when I do:
or set
class_name
to any string or symbol, I get the result ofMember.first.to_s
for the class name.Also, setting the option,
object_id: false
does not seem to help.The text was updated successfully, but these errors were encountered: