Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想创造一个动态的条件。它看起来像
Model.send("attr_name") > 0 ? true : false
但是我怎样才能动态地写符号“>”呢?
我不太明白你的问题是什么,但这可能是答案:
1.9.3p194 :004 > s = "<" => "<" 1.9.3p194 :005 > 0.send :"#{s}", 1 => true
您不需要三元运算符? :。它可以简单地写成:
? :
Model.send("attr_name").send(condition,0)
失去显示:内联属性