Publishers.const_get(provider_name).new(@photo)
Nested class from a string
-
12-10-2022 - |
문제
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?
해결책
제휴하지 않습니다 StackOverflow