ker*_*lin 4 ruby variables methods ruby-on-rails dynamic
可能重复:
使用Ruby中的函数名称从字符串调用函数
我想做这样的事情:
def self.greater_than(col_str='events')
self."#{col_str}"_greater_than(30) # search logic scope method
end
Run Code Online (Sandbox Code Playgroud)
我怎样才能正确调用它?我猜测语法可能与创建动态方法类似.
the*_*eIV 12
你可以尝试使用 send
send("#{col_str}_greater_than".to_sym, 30)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6534 次 |
| 最近记录: |