最佳答案
尝试通过以下方法动态创建对象和调用方法
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
有人可以帮助我如何发送多个参数到一个 Ruby 方法动态