Variables allow you to control specific aspects of your features dynamically. They are associated with feature flags and can be used to customize feature behavior.

Accessing Variables

After fetching a feature flag, you can access its variables using the get_variable() method:

get_flag_response = vwo_instance.get_flag('feature_key', { id: 'your_user_id'})

# check if feature is enabled
puts get_flag_response.is_enabled()
# get all variables
puts get_flag_response.get_variables()
# get specific variable
puts get_flag_response.get_variable('variable_key', 'default_value')
 
ParameterTypeDescription
key
Required
stringThe name of the variable.
defaultValue
Required
hashThe default value to return if the variable is not found.

get_variables() Method

variables = get_flag_response.get_variables()
variables.each do |variable|
  puts "Key: #{variable['key']}, Value: #{variable['value']}"
end

This method returns a slice of maps, where each map represents a variable with its key and value.
Remember that variables must be defined in your VWO dashboard for the corresponding feature flag before you can use them in your code.