在模型委托声明中使用数组符号
问题描述:
我正试图在我的模型中动态地将一些值传递给delegate
。我有参数作为一组符号:在模型委托声明中使用数组符号
[:first_name,
:first_name=,
:last_name,
:last_name=,
:email,
:email=]
我该如何使用它? Array#join
将我的每个元素转换为不合适的字符串。我需要包括上述这样的数组:
delegate <ARRAY-OF-SYMBOLS-HERE,
to: :my_other_class
prefix: :my_prefix
答
你可以简单地直接传递你的数组delegate
方法:
delegate symbols_array, to: :my_other_class, prefix: :my_prefix
无需'图示(*)'。 ['delegate()'](http://apidock.com/rails/Module/delegate)接受数组作为参数'delegate(* methods)'。所以'代表(* symbols_array)''委托(symbols_array)'相同' – 2014-10-27 09:46:21
@Зелёный你是对的。感谢您的建议。你不像你自称的那么绿。 :) – 2014-10-27 09:59:00