我是ruby的新手.我正在尝试编写一个apache error.log监视器.它主要完成了,但我收到了警告:否则没有救援就没用了.
我无法弄清楚我做错了什么. Ruby要我使用’除非’吗?
我无法弄清楚我做错了什么. Ruby要我使用’除非’吗?
class ErrorMonitor @@prevIoUs_size=0 @@counter=0 def initialize() end def process if @@counter > 0 @new_size= File.stat('/var/log/apache2/error.log').size if @new_size > @@prevIoUs_size for i in @@prevIoUs_size..@new_size - @@prevIoUs_size print IO.readlines("/var/log/apache2/error.log")[i] end @@prevIoUs_size = @new_size end end else @@prevIoUs_size= File.stat('/var/log/apache2/error.log').size @@counter=1; end # <- this line is where the warning points to end # main execution em = ErrorMonitor.new() while true em.process sleep 10 end
解决方法
if condition # … else # … end
不
if condition # … end else # … end