ruby-style-guide
ruby-style-guide copied to clipboard
`extend`ing objects at runtime
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 https://github.com/rubocop-hq/rubocop/pull/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)?
I agree that's something to be avoided. I feel similarly about requiring stuff outside of the top-level scope.
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 😆 )