mercredi 1 avril 2020

simple ruby unless method mistake

I am very new to ruby. This might sound very naive to you but I can't understand what is happening here

matched_criteria = match_criteria(c1, c2)
puts "answer is #{matched_criteria}"

def match_criteria(crit_val1, crit_val2)
  if crit_val1.present?
    puts "present"
  else
    puts "absent"
  end

  return true unless crit_val1.present? || crit_val2.present?
  return false unless crit_val1.present? && crit_val2.present?
end

Output: absent answer is false

please explain

Aucun commentaire:

Enregistrer un commentaire