开发者

Ruby syntax accept arguments on dynamically generated methods via send

开发者 https://www.devze.com 2023-04-06 20:38 出处:网络
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.

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

精彩评论

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

关注公众号