1

What does it mean when the bang method is in front? What is this shorthand for?

!post.save
the Tin Man
  • 155,156
  • 41
  • 207
  • 295
alenm
  • 961
  • 2
  • 13
  • 30

2 Answers2

6

It's a negation. In your example it means to NOT the result of post.save.

if:

post.save => true
!post.save => false

otherwise:

post.save => false
!post.save => true
TreyE
  • 2,489
  • 21
  • 23
6

It is equivalent to

not post.save

Usually used in if clauses, like:

if !post.save               #if the post could not be saved for some reason
   puts 'could not save post!'
end

It's because the function save from ActiveResource::Base returns true if the POST request succeeded and false if it didn't. Read here for some more information about the function.

Ivan Zarea
  • 2,164
  • 15
  • 13