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

Improve inspect readability #162

Merged

Conversation

neilvcarvalho
Copy link
Contributor

While debugging code backed by StoreModel, I had issues understanding some model attributes, as those that were more complex objects just printed the attribute's class and its memory address.

I saw something like:

=> #<Content::Text type: text, text: #<Content::Text::Base:0x000000011a9716f0>>

By contrast, the default Ruby inspect implementation calls inspect on all the object's instance variables:

=> #<OuterClass:0x0000000104ac87f8 @attribute=#<InnerClass:0x000000010466cf60 @text="string">>

Also, the strings are not quoted, making strings like "nil" and "false" show up as nil and false, which may lead to confusion.

This commit changes the inspect implementation to call inspect on the model attributes, fixing the issues stated above.

While debugging code backed by `StoreModel`, I had issues understanding
some model attributes, as those that were more complex objects just
printed the attribute's class and its memory address.

I saw something like:

```
=> #<Content::Text type: text, text: #<Content::Text::Base:0x000000011a9716f0>>
```

By contrast, the default Ruby `inspect` implementation calls `inspect`
on all the object's instance variables:

```
=> #<OuterClass:0x0000000104ac87f8 @Attribute=#<InnerClass:0x000000010466cf60 @text="string">>
```

Also, the strings are not quoted, making strings like `"nil"` and
`"false"` show up as `nil` and `false`, which may lead to confusion.

This commit changes the `inspect` implementation to call `inspect` on
the model attributes, fixing the issues stated above.
Copy link
Owner

@DmitryTsepelev DmitryTsepelev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, thank you 🙂

@DmitryTsepelev DmitryTsepelev merged commit 95fdb9b into DmitryTsepelev:master Nov 16, 2023
9 checks passed
@neilvcarvalho neilvcarvalho deleted the nc-inspect-more-readable branch November 16, 2023 21:10
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

Successfully merging this pull request may close these issues.

2 participants