문제

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?

도움이 되었습니까?

해결책

Publishers.const_get(provider_name).new(@photo)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top