我无法编译将类型从整数转换为字符串的代码.我正在运行Rust for Rubyists教程中的一个示例,该教程具有各种类型转换,例如:
"Fizz".to_str()和 num.to_str()(其中num是整数).
我认为这些to_str()函数调用的大部分(如果不是全部)都已被弃用.将整数转换为字符串的当前方法是什么?
我得到的错误是:
error: type `&'static str` does not implement any method in scope named `to_str`
error: type `int` does not implement any method in scope named `to_str`
Run Code Online (Sandbox Code Playgroud) 我试图找出一种方法,通过将ActiveRecord模型与常规方法混合使用的常规rails 3.0语法进行搜索。
例如:
class User < ActiveRecord::Base
def custom_method
if [...]
return true
else
return false
end
end
end
Run Code Online (Sandbox Code Playgroud)
并且我想以这种方式使用ActiveRecord来激活它:
User.find(:all).where(custom_method is true)
Run Code Online (Sandbox Code Playgroud)
有什么办法吗?抱歉,如果语法与我要传达的内容不正确。
编辑:我想澄清一下,custom_method使用起来是相当复杂的,因此最好将其调用而不是将其转换为sql语法。
这可能是一个愚蠢的问题,但我的rails应用程序开始受到这种代码风格的困扰:
def return_my_object
@object = get_object
some_function_work(@object)
return @object
end
Run Code Online (Sandbox Code Playgroud)
是否有一般做法或方法来摆脱或避免return @object代码?到目前为止,我无法想到任何东西,它似乎是残酷的代码.