General outline or use agreement! at the end of the method in rails indicates that the function can throw an exception, compared to the non-bang method, which simply returns a value.
The consequence of the exclusion of metadata allows the return value to be used as part of normal processing.
if obj.save
# yay, it worked!
else
# boo
end
Please note that this is not a rule applied by Ruby, just a convention. Other libraries, such as the standard library for String, have methods that return the result of an operation or change the value of an object in place.
String s = "Hello, world"
s.gsub ("world", "Joe") # returns a new string object, leaving s alone
s.gsub! ("world", "Joe") # modifies the value of s
source share