Christian Mayer's Weblog

Ruby: Prevent Multi-line Statement Bugs

What’s wrong here?

if @foreign_id_opt.nil? && @unset_foreign_id_opt.nil?
	@name_opt.nil? && @description_opt.nil? &&
	@estimation_opt.nil?
	
	raise TaskCommandError, "No option given. See 'timr task -h'."
end

Straight at the end of the first line there is an AND && missing. The second and third line is pointless. They are not part of the if condition.

To prevent such a mistake append a backslash \ to each line of the multi-line statement:

if @foreign_id_opt.nil? && @unset_foreign_id_opt.nil? && \
	@name_opt.nil? && @description_opt.nil? && \
	@estimation_opt.nil?
	
	raise TaskCommandError, "No option given. See 'timr task -h'."
end

See the original issue on Timr@41e9cd commit.

Posted on by Christian Mayer.
Categories: Programming. Tags: Ruby, If, Multi-line Statement, Bug.

Imprint | Usage | Archive | Categories | Feed
Copyright © 2006 by