Sha256: 9b0af9af137b3783df03ae15aad104a1a327f4cea63f6e7468c8ed5aa1e41469
Contents?: true
Size: 646 Bytes
Versions: 6
Compression:
Stored size: 646 Bytes
Contents
module Metry class Experiment METHODS = { "rand" => proc{|list, visitor| list.sort_by{rand}.first}, "mod_visitor" => proc{|list, visitor| list[(visitor['_id'].to_i-1)%list.size]}, # mod_visitor will only work with predictable_keys = true } def initialize(name, event, visitor) @key = "experiment:#{name}" @event = event @visitor = visitor end def choose(options, method=nil) unless choice = @visitor[@key] choice = METHODS[method || "rand"][options.keys, @visitor] @visitor[@key] = choice end @event[@key] = choice options[choice] end end end
Version data entries
6 entries across 6 versions & 1 rubygems