Created
September 11, 2009 21:14
-
-
Save eric1234/185587 to your computer and use it in GitHub Desktop.
Example code used in blog comment at http://robots.thoughtbot.com/post/185504560/to-self-or-not-to-self
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An example of verbose Ruby code to counter the argument that | |
# optional syntax should be used as expressed on the blog post | |
# http://robots.thoughtbot.com/post/185504560/to-self-or-not-to-self | |
# | |
# I.E. the logical conclusion of this sort of thinking. | |
class User < ActiveRecord::Base | |
self.before_save(:sanitize_names); | |
def display_name() | |
return self.email() if self.first_name().blank?(); | |
return [self.first_name(), self.last_name()].compact().join(" "); | |
end | |
protected(); | |
def sanitize_names() | |
self.first_name = nil if self.first_name().blank?(); | |
self.last_name = nil if self.last_name().blank?(); | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment