From 1bce43d6a51ee09631f55cf427a2e110d901ecb2 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Mon, 2 Oct 2017 16:54:33 +0200 Subject: Don't validate again when checking if valid. Unless validation has not yet been performed, of course. --- lib/band.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'lib/band.rb') diff --git a/lib/band.rb b/lib/band.rb index 9b949c7..dc69642 100644 --- a/lib/band.rb +++ b/lib/band.rb @@ -7,7 +7,6 @@ class Band attr_accessor :errors def initialize(params = nil) - @errors = [] @contact = Contact.new @members = "" @songs = [] @@ -31,13 +30,13 @@ class Band end def valid? - validate! - errors.length == 0 + validate! unless errors + !has_errors? end def validate! @errors = [] - + if @name.nil? || @name.strip.empty? errors << "Bandnavn mangler" end @@ -49,8 +48,8 @@ class Band end end - def has_errors - errors.length > 0 + def has_errors? + errors && errors.length > 0 end def name_and_city -- cgit v1.2.3