Skip to content

Instantly share code, notes, and snippets.

@nickhoffman
Created January 13, 2012 21:06
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 nickhoffman/1608697 to your computer and use it in GitHub Desktop.
Save nickhoffman/1608697 to your computer and use it in GitHub Desktop.
Would you duplicate the validation's regex, or reference a constant?
class User
field :username, :type => String
validates :username, :format => { :with => /\A[[:print:] ]{3,20}\Z/ }
end
class ScoreCard
belongs_to :user
field :username, :type => String
validates :username, :format => { :with => /\A[[:print:] ]{3,20}\Z/ }
end
class User
USERNAME_REGEX = /\A[[:print:] ]{3,20}\Z/
field :username, :type => String
validates :username, :format => { :with => USERNAME_REGEX }
end
class ScoreCard
belongs_to :user
field :username, :type => String
validates :username, :format => { :with => User::USERNAME_REGEX }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment