Próba tworzenia obiektów i metod zadzwonić dynamicznie przezrubin wysłać metodę przejściu wielu parametrów
Object.const_get(class_name).new.send(method_name,parameters_array)
który działa dobrze, gdy
Object.const_get(RandomClass).new.send(i_take_arguments,[10.0])
ale rzuca zły numer argumentów 1 do 2 dla
Object.const_get(RandomClass).new.send(i_take_multiple_arguments,[25.0,26.0])
Zdefiniowana klasa losowa to
class RandomClass
def i_am_method_one
puts "I am method 1"
end
def i_take_arguments(a)
puts "the argument passed is #{a}"
end
def i_take_multiple_arguments(b,c)
puts "the arguments passed are #{b} and #{c}"
end
end
Czy ktoś może mi pomóc w jaki sposób wysłać mutiple parametrów do metody ruby dynamicznie
Może warto zauważyć, że '*' w tym kontekście jest operatorem "splat". –