I forgot. Does the exclamation mark mean not?



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
  raise RecordInvalid.new(record) if !saved && raise_error


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


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