Module: Vanity::Experiment::Definition
- Defined in:
- lib/vanity/experiment/base.rb,
lib/vanity/experiment/ab_test.rb
Overview
These methods are available from experiment definitions (files located in the experiments directory, automatically loaded by Vanity). Use these methods to define you experiments, for example:
ab_test "New Banner" do alternatives :red, :green, :blue metrics :signup end
Instance Attribute Summary (collapse)
-
- (Object) playground
readonly
Returns the value of attribute playground.
Instance Method Summary (collapse)
-
- (Object) ab_test(name, &block)
Define an A/B test with the given name.
-
- (Object) define(name, type, options = nil, &block)
Defines a new experiment, given the experiment’s name, type and definition block.
- - (Object) new_binding(playground, id)
Instance Attribute Details
- (Object) playground (readonly)
Returns the value of attribute playground
13 14 15 |
# File 'lib/vanity/experiment/base.rb', line 13 def playground @playground end |
Instance Method Details
- (Object) ab_test(name, &block)
Define an A/B test with the given name. For example:
ab_test "New Banner" do alternatives :red, :green, :blue end
501 502 503 |
# File 'lib/vanity/experiment/ab_test.rb', line 501 def ab_test(name, &block) define name, :ab_test, &block end |
- (Object) define(name, type, options = nil, &block)
Defines a new experiment, given the experiment’s name, type and definition block.
17 18 19 20 21 22 23 24 |
# File 'lib/vanity/experiment/base.rb', line 17 def define(name, type, = 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, ) experiment.instance_eval &block experiment.save playground.experiments[@experiment_id] = experiment end |
- (Object) new_binding(playground, id)
26 27 28 29 |
# File 'lib/vanity/experiment/base.rb', line 26 def new_binding(playground, id) @playground, @experiment_id = playground, id binding end |