Skip to content

Add Initializers section to properties documentation #10

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

christopher-b
Copy link
Contributor

I discovered the after_initialize hook while exploring how properties interact with the initializer. I'm sure other folks would find this useful.

I discovered the `after_initialize` hook while exploring how properties interact with the initializer. I'm sure other folks would find this useful.
Comment on lines 96 to 98
def after_initialize
@name = @name.strip
end
Copy link
Collaborator

@joeldrapper joeldrapper Apr 3, 2025

Choose a reason for hiding this comment

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

It’s good to document this, but I think we should come up with a better example. I would use a coercion for this.

prop :name, String, &:strip

Perhaps something that compares two values against each other, like if we have min and max, we could raise here if min is greater than max.

Though even in that case, I would prefer to use a Range which will manage this or you. 😆

It’s hard to come up with good examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about something like PersonRepository.add(self)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or even just

  def after_initialize
    # Your initialization logic
  end

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