Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4612

Ruby dynamically determine class and calling methods

$
0
0

I have a factory module which returns class, like this

# frozen_string_literal: truemodule Factory  module Subscriptions    module SubscriptionSelector      class << self        def select_by_plan_type_for_subscription(plan)          case plan.type          when 'UpsellSubscription'            UpsellSubscription          else            NewSubscription          end        end      end    end  endend

and I am using this module like this

subscription = Factory::Subscriptions::SubscriptionSelector                       .select_by_plan_type_for_subscription(plan)                       .create!(                         account: account,                         product: plan.product,                         status: 'active',                         active_plan: plan,                         active_plan_end_date: end_date,                         renewal_date: end_date                       )

but somehow my tests are failing with NameError: uninitialized constant Factory::Subscriptions::SubscriptionSelector

both NewSubscription and UpsellSubscription are ActiveRecord and they share same logics via concern

Trying to write factory method for dynamically class calling


Viewing all articles
Browse latest Browse all 4612

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>