我遇到了一个有趣的问题,下面是相对简单的作业。开始的每个括号内的块都评估为零,而Rubygame::Surface.new
应该被指定为@image
的值。不幸的是,在我设置@rect
的下一行中,它会抛出NoMethodError,因为@image
是无。简单'或'不按预期方式工作
@image = (image unless image.nil?) or
(Rubygame::Surface.autoload(image_file) unless image_file.nil?) or
(Rubygame::Surface.autoload("#{@name}.png") unless @name.nil?) or
Rubygame::Surface.new([16, 16])
@rect = Rubygame::Rect.new [0, 0], [@image.width, @image.height]
类似的测试通过IRB工作按预期运行,所以我敢肯定的“或”语句是良好的,但我想不通为什么它没有返回新的表面时,一切否则是零。
只有一条第一条线已经在吹我的头... – Nakilon 2010-09-11 10:05:33
'image除非image.nil?' - >'图像如果图像 - >'图像' – Nakilon 2010-09-11 10:07:30
重复的http://stackoverflow.com/questions/2083112/ – 2010-09-12 23:30:52