I'm trying to do a method for choosing an AB test option in Rails, according to a test result. I would like to find a more efficient way of doing the first nil test: If given option A is nil, return B If given option B is nil, return A
module AbTestHelper
def ab_test_choice(ab_test_name, option_a, option_b, *args)
#This part
return option_b unless option_a
return option_a unless option_b
#This part
check_test_enabled = "#{ab_test_name}_enabled?"
test_result = send(check_test_enabled, args) if respond_to? check_test_enabled
return option_a if result
option_b
end
private
def colour_enabled?(user = current_user)
return unless user.is_a? User
user.enabled_for?(:colour)
end
end