下面有代码,但无法运行:
%w(acp bcp ccp tcp).each do |kind|
define_method(kind+"_name") { send "[#{kind}_title ? #{kind}_title.title : '',#{kind}_firstname,#{kind}_lastname].join(' ')" }
end在运行时:
> Form.last.acp_name
NoMethodError: undefined method `[acp_title ? acp_title.title : '',acp_firstname,acp_lastname].join(' ')' for #<Form:0x108daabe8>有谁知道如何修复它以代码而不是文字的形式运行?
提前谢谢..。
发布于 2013-09-05 15:04:25
%w(acp bcp ccp tcp).each do |kind|
define_method("#{ kind }_name") do
title = send("#{ kind }_title") || ''
array = [ title, send("#{ kind }_firstname"), send("#{ kind }_lastname")]
array.join(' ')
end
endhttps://stackoverflow.com/questions/18639758
复制相似问题