Question

I want to call a method on a class in the namespace of Publishers, such as Publishers::Vk, where the nested part is expressed as a string like provider_name = 'Vk'. I did something like that:

send("Publishers::#{provider_name}.new(#{@photo})")

I get an exception:

undefined method `Publishers::Vk.new(#<Photo:0x000000085e5440>)' for #<PhotoPublisher:0x00000008616c98>

How can I implement this functionality?

Was it helpful?

Solution

Publishers.const_get(provider_name).new(@photo)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top