Skip to content

Instantly share code, notes, and snippets.

@eric1234
Created September 11, 2009 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eric1234/185587 to your computer and use it in GitHub Desktop.
Save eric1234/185587 to your computer and use it in GitHub Desktop.
# 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