-1

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?

sawa
  • 165,429
  • 45
  • 277
  • 381
Alex Antonov
  • 14,134
  • 7
  • 65
  • 142

1 Answers1

3
Publishers.const_get(provider_name).new(@photo)
Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367