Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
omkarmoghe committed Apr 19, 2024
1 parent 3a3a6d4 commit 91189ce
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions lib/lab_coat/experiment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(name)

# Override this method to control whether or not the experiment runs.
# @return [TrueClass, FalseClass]
def enabled?(...)
def enabled?
raise InvalidExperimentError, "`#enabled?` must be implemented in your Experiment class."
end

Expand Down Expand Up @@ -69,6 +69,7 @@ def run!(**context)
raised(control_obs) if control_obs.raised?
return control_obs.value unless enabled?

# Run the candidate.
candidate_obs = Observation.new("candidate", self) { candidate }
raised(candidate_obs) if candidate_obs.raised?

Expand All @@ -82,17 +83,5 @@ def run!(**context)
# Always return the control.
control_obs.value
end

private

# Because `run!` forwards arbitrary args to `#enabled?`, `control`, and `candidate`, the methods must have the same
# arity. Otherwise
def enforce_arity!
return if %i[enabled? control candidate].map { |m| method(m).arity }.uniq.size == 1

raise InvalidExperimentError,
"The `#enabled?`, `#control` and `#candidate` methods must have the same arity. All runtime args passed " \
"to `#run!` are forwarded to these methods."
end
end
end

0 comments on commit 91189ce

Please sign in to comment.