Is there a better way to write this condition down?
if (self.expense.nil? && self.income.nil?) || (!self.expense.nil? && !self.income.nil?) puts "test" end
You check if the expressions are true or false. Try the following:
if (self.expense.nil? == self.income.nil?)
You don't care if they are true or false, they just are the same.
Despite the logic, since you use if to check for zero, you can shorten the code as follows:
if ((expense && income) || (!expense && !income)) puts "test" end
Correct me if I am wrong.
You can use Demorgan law for the second half of the if condition
therefore (!self.expense.nil? && !self.income.nil?)it becomes!(self.expense.nil? || self.income.nil?)
(!self.expense.nil? && !self.income.nil?)
!(self.expense.nil? || self.income.nil?)
Source: https://habr.com/ru/post/1759001/More articles:InstantationException in newInstance of an anonymous class created - javaNSFetchRequest setFetchOffset in NSFetchedResultsController - iphoneStop select.change from sending back - javascripthow to add ajax on django admin - djangoFlash cannot trigger any events on URLLoader - flashrspec expects throws "undefined method" - ruby | fooobar.comAndroid ListView Move to cursor position - androidWeb Service for Weather - c #Delphi 2010 RTTI - как я могу получить список индексированных свойств? - rttiDynamic arrays in VBScript with Split (). Is there a better way? - arraysAll Articles