gpt4 book ai didi

ruby-on-rails - Rails - 变量作为方法名称的一部分

转载 作者:数据小太阳 更新时间:2023-10-29 07:22:41 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Calling a Function From a String With the Function's Name in Ruby

我想做这样的事情:

  def self.greater_than(col_str='events')
self."#{col_str}"_greater_than(30) # search logic scope method
end

我怎样才能让它正确调用?我猜语法可能类似于创建动态方法。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com