有沒有人注意到這樣的事情?爲什麼會發生?奇怪的行爲總和在軌道上的紅寶石控制檯
ruby-1.9.2-p290 :006 > User.count
(0.4ms) SELECT COUNT(*) FROM "users"
=> 102
ruby-1.9.2-p290 :007 > User.count + 1
(0.4ms) SELECT COUNT(*) FROM "users"
=> 103
ruby-1.9.2-p290 :008 > User.count+ 1
(0.4ms) SELECT COUNT(*) FROM "users"
=> 103
ruby-1.9.2-p290 :009 > User.count+1
(0.4ms) SELECT COUNT(*) FROM "users"
=> 103
ruby-1.9.2-p290 :010 > User.count +1
(0.5ms) SELECT COUNT(1) FROM "users"
=> 102
使用ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
& & Rails 3.1.3
額外的東西:
ruby-1.9.2-p290 :007 > "ayay".length + 1
=> 5
ruby-1.9.2-p290 :008 > "ayay".length +1
ArgumentError: wrong number of arguments(1 for 0)
from (irb):8:in `length'
...
奇怪。並且「(User.count)+1」返回「103」。順便說一句,它是可重現的紅寶石1.8.7 /導軌2.3.8,甚至在jruby /導軌3.1 – buru