开发者

Ruby syntax accept arguments on dynamically generated methods via send

How I can pass arguments on dynamically generated methods via send ?

Below I generate on the fly several methods, I want th开发者_开发百科ey 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


(class << self; self end).send :define_method, attr do |row|
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜