Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The exclamation mark has a reason: if the newly created records fails validations, an exception is raised. Without the exclamation mark, the error is silenced (and the method returns a falsey value). This is a convention across Rails.

Ruby itself mostly uses it for mutating methods (e.g. #gsub("a", "b") replaces the character a with b in a string and returns a new string, but #gsub!("a", "b") mutates the original.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: