Skip to content
A light weight ruby AB test library based on rules
Ruby
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
spec
.gitignore
.rspec
Gemfile
Gemfile.lock
MIT-LICENSE
README.md
ab_rules.gemspec

README.md

AbRules

AbRules is a light ruby library to fulfill A/B testing.

Inspired by Split, AbRules aims to simplify the A/B testing logic, focus on providing flexible rules to generate different contents.

Requirements

  • Ruby 1.9.3 or higher

Setup

gem install ab_rules

Usage

Example: A/B testing by ID

require "ab_rules"

AbRules.split_by_id(122, "control", "test")  #=> "control"
AbRules.split_by_id(333, "control", "test")  #=> "test"

AbRules.split_by_id(333, "control", "test") do |alternative|
  "The version is #{alternative}"
end

#=> "The version is test"

Example: A/B testing by rules

require "ab_rules"

SITES = [123, 567, 999]
NETWORKS = [1, 4, 6]

rules = [
  AbRules.rule(:control) do |subjects|
    subjects[:country] == "uk"
  end,

  AbRules.rule(:test) do |subjects|
    subjects[:id] && subjects[:id].even?
  end,

  AbRules.rule(:default)
]

AbRules.split_by_rule({ country: "uk" }, rules)  #=> :control
AbRules.split_by_rule({ id: 2 }, rules)  #=> :test
AbRules.split_by_rule({}, rules) do |content|
  "Cotent is #{content}"
end
#=> "Cotent is default"

Questions, Feedback

Feel free to message me on Github (fdf515) or Twitter (@JIAZHENXIE) :)

Contributing to AbRules

Fork, fix, then send a pull request.

Copyright

Copyright (c) 2015 Jiazhen Xie. See MIT-LICENSE for further details.

You can’t perform that action at this time.