オブジェクトを作成してメソッドを動的に呼び出そうとする
Object.const_get(class_name).new.send(method_name,parameters_array)
うまくいっているとき
Object.const_get(RandomClass).new.send(i_take_arguments,[10.0])
間違った数の引数をスローする
Object.const_get(RandomClass).new.send(i_take_multiple_arguments,[25.0,26.0])
定義されているランダムクラスは
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
誰かが動的にルビメソッドに複数のパラメータを送信する方法を手伝ってくれる?
*
このコンテキストでは「splat」演算子であることに注意してください。