Skip to content

Instantly share code, notes, and snippets.

@johana-star
Created January 9, 2017 18:16
Show Gist options
  • Save johana-star/45b08e0955741d555dc3e40cf710df7a to your computer and use it in GitHub Desktop.
Save johana-star/45b08e0955741d555dc3e40cf710df7a to your computer and use it in GitHub Desktop.
Github Scientist example

GitHub's Scientist gem provide's a framework for running and publishing experiments, however, I found their code snippets a little confusing. They confused me because the examples were either too simple (that is, did not demonstrate the publishing feature) or they were incomplete (that is, they assumed the user had some implementation correctly setup and just needed to add code to make it run).

This is the shortest hello world style example which demonstrates publishing I could figure out.

require 'scientist'
class Greeter
include Scientist
include Scientist::Experiment
def initialize(*args)
end
def greeting
science "say_hello" do |experiment|
experiment.use { "hello" }
experiment.try { "hola" }
end
end
def enabled?
true
end
def publish(result)
p result
end
end
# replace `Scientist::Default` as the default implementation
module Scientist::Experiment
def self.new(name)
Greeter.new(name: name)
end
end
puts Greeter.new.greeting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment