Skip to main content

Ruby Server SDK Usage

RubyGems GitHub

User Object

The full user data must be passed into every method. The only required field is user_id. The rest are optional and are used by the system for user segmentation into variables and features.

See the User model in the Ruby user model doc for all accepted fields including custom fields.

user ={ user_id: 'user_id_example' })

Get and use Variable by key

To get values from your Variables, devcycle_client.variable_value() is used to fetch variable values using the user data, variable key, coupled with a default value for the variable. The default variable will be used in cases where the user is not segmented into a feature using that variable, or the project configuration is unavailable to be fetched from DevCycle's CDN.

# Get value of given variable by key, using default value if segmentation is not passed or variable does not exit
result = devcycle_client.variable_value("variable-key", user, true)
p "Received value for 'variable-key': #{result}"
puts "Exception when calling DevCycle::Client->variable_value"

The default value can be of type string, boolean, number, or object.

If you would like to get the full Variable you can use devcycle_client.variable() instead. This contains fields such as: key, value, type, defaultValue, isDefaulted.

Getting all Features

You can fetch all segmented features for a user:

# Get all features for user data
result = devcycle_client.all_features(user)
p result
puts "Exception when calling DevCycle::Client->all_features"

Getting all Variables

To grab all the segmented variables for a user:

# Get all variables for user data
result = devcycle_client.all_variables(user)
p result
puts "Exception when calling DevCycle::Client->all_variables"

Track Events

Track a custom event for a user, pass in the user and event object.

Calling Track will queue the event, which will be sent in batches to the DevCycle servers.

event_data ={
type: "my-event",
target: "some_event_target",
value: 12,
meta_data: {
myKey: "my-value"

# Post events for given user data
result = devcycle_client.track(user, event_data)
p result
rescue => e
puts "Exception when calling DevCycle::Client->track: #{e}"

Override Logger

To provide a custom logger, override the logger property of the SDK configuration.

options = @yourCustomLogger)

Set Client Custom Data

To assist with segmentation and bucketing you can set a custom data hash that will be used for all variable and feature evaluations. User specific custom data will override this client custom data.

# Set client custom data
custom_data = {"some-key" : "some-value"}
rescue => e
puts "Exception when calling DevCycle::Client->set_client_custom_data: #{e}"

Client Custom Data is only available for the Local Bucketing SDK


EdgeDB allows you to save user data to our EdgeDB storage so that you don't have to pass in all the user data every time you identify a user. Read more about EdgeDB.

To get started, contact us at [email protected] to enable EdgeDB for your project.

Once you have EdgeDB enabled in your project, pass in the enableEdgeDB option to turn on EdgeDB mode for the SDK:

# Load the gem
require 'devcycle-ruby-server-sdk'

# Setup authorization
options = true, enable_cloud_bucketing: true)

devcycle_client ="dvc_server_token_hash", options, true)
user ={
user_id: 'test_user',
email: '[email protected]',
country: 'CA'

This will send a request to our EdgeDB API to save the custom data under the user test_user.

In the example, Email and Country are associated to the user test_user. In your next identify call for the same user_id, you may omit any of the data you've sent already as it will be pulled from the EdgeDB storage when segmenting to experiments and features.