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

extending objects at runtime #846

Open
marcandre opened this issue Oct 10, 2020 · 2 comments
Open

extending objects at runtime #846

marcandre opened this issue Oct 10, 2020 · 2 comments
Labels

Comments

@marcandre
Copy link
Contributor

I've always avoided extending objects at runtime, like in this example:

class Polymorphic
  def initialize(style: :foo)
    extend Something if style == :bar
    # ...
  end
end

It used to be that performance could be severely impacted but it's not clear it's still the case today (see rubocop/rubocop#8881 )
Style-wise, it seems to complicate things and make introspection / debugging / branch-covering more difficult.

Is that an accepted principle to avoid this (and if so, is it still valid)?

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 21, 2020

I agree that's something to be avoided. I feel similarly about requiring stuff outside of the top-level scope.

@marcandre
Copy link
Contributor Author

requiring stuff outside of the top-level scope.

I feel this is a very different issue (and I'd love to argue in favor of that if you want to open an issue 😆 )

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

No branches or pull requests

2 participants