module Vanity::Experiment::Definition

These methods are available from experiment definitions (files located in the experiments directory, automatically loaded by Vanity). Use these methods to define your experiments, for example:

ab_test "New Banner" do
  alternatives :red, :green, :blue
  metrics :signup
end

Attributes

playground[R]

Public Instance Methods

ab_test(name, &block) click to toggle source

Define an A/B test with the given name. For example:

ab_test "New Banner" do
  alternatives :red, :green, :blue
end
# File lib/vanity/experiment/ab_test.rb, line 699
def ab_test(name, &block)
  define name, :ab_test, &block
end
define(name, type, options = nil, &block) click to toggle source

Defines a new experiment, given the experiment's name, type and definition block.

# File lib/vanity/experiment/definition.rb, line 16
def define(name, type, options = nil, &block)
  fail "Experiment #{@experiment_id} already defined in playground" if playground.experiments[@experiment_id]
  klass = Experiment.const_get(type.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase })
  experiment = klass.new(playground, @experiment_id, name, options)
  experiment.instance_eval(&block)
  experiment.save
  playground.experiments[@experiment_id] = experiment
end
new_binding(playground, id) click to toggle source
# File lib/vanity/experiment/definition.rb, line 25
def new_binding(playground, id)
  @playground, @experiment_id = playground, id
  binding
end