Ruby 语法通过 send 接受动态生成的方法上的参数
如何通过 send 在动态生成的方法上传递参数?
下面我动态生成几个方法,我希望它们接受“行”参数。
下面的代码生成方法,但我不知道如何让这些方法接受“行”参数。
@sql_columns.each do |attr|
(class << self; self end).send :define_method, attr do
key = @column_mapping[attr].to_s
row[key]
end
end
How I can pass arguments on dynamically generated methods via send ?
Below I generate on the fly several methods, I want they accept the "row" argument.
The code below generates the methods, but I don't know how let the methods accept the "row" argument.
@sql_columns.each do |attr|
(class << self; self end).send :define_method, attr do
key = @column_mapping[attr].to_s
row[key]
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)