新手问题 attribute? 方法的返回值问题

wym205 · August 28, 2013 · Last by wym205 replied at August 28, 2013 · 2244 hits

class User < ActiveRecord::Base attr_accessible :age end user = User.new user.id = 0 user.id? #false user.age = 0 user.age? #false

很奇怪上面那段代码中的两个 false 的返回值,!!0 为什么不是 true 呢

Rails 源代码中返回 false 的应该是这句:!value.to_i.zero?

thanks,原来是看错源代码了

You need to Sign in before reply, if you don't have an account, please Sign up first.