github / scientist

:microscope: A Ruby library for carefully refactoring critical paths.
MIT License
7.44k stars 439 forks source link

Don’t set default when included in modules #144

Closed jejacks0n closed 3 years ago

jejacks0n commented 3 years ago

This came up recently on some work on gitlab, where we're using scientist for some of our experimentation work.

Ultimately I was extracting some of the base experiment behavior into a module, and realize that in doing this, it sets the default @experiment_klass to a module, and that breaks when trying to use the science method. So basically it doesn't seem like the included callback should be setting the default class if it's a module.

The only way to get around this is to:

module MyModule
  Scientist::Experiment.send(:append_features, self)
  extend Scientist::Experiment::RaiseOnMismatch

  #... implementation
end

Which doesn't really seem right. I know we can do Scientist::Experiment.set_default(nil), but that then has load order implications and so we just don't want the behavior in general and feel like we're trying to work around a convenience that's actually somewhat hard to work around.

Thoughts?

coveralls commented 3 years ago

Coverage Status

Coverage remained the same at 99.103% when pulling a6222a6158e25dc5d7baa00d3cbc1e92b96c0e3c on jejacks0n:no-set-default-for-module into 15ca554bbb83c73c92e00ba478dab86c7805304c on github:master.

zerowidth commented 3 years ago

Makes sense. I'll add some documentation mentioning this and cut a 1.6.0 release.