I forgot. Does the exclamation mark mean not?


#1


https://www.codecademy.com/en/courses/ruby-beginner-en-MFiQ6/1/5?curriculum_id=5059f8619189a5000201fbcb

Does the exclamation mark in 'if !saved ...' mean not?


def create_record(attributes, raise_error = false)
  record = build_record(attributes)
  yield(record) if block_given?
  saved = record.save
  set_new_record(record)
  raise RecordInvalid.new(record) if !saved && raise_error
  record
end


#2

We can think of it as NOT, while bearing in mind that it is negation, with the yield being a boolean.

saved = false
print !saved     # true

The value of the variable need not be a boolean.

saved = "saved"
print !saved     # false

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.