Skip to content

Instantly share code, notes, and snippets.

View acadavid's full-sized avatar

Alejandro Cadavid acadavid

View GitHub Profile
validates :email, presence: true, format: { with: /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/ }
validates :username, presence: true, length: { :minimum => 3 },
uniqueness: true, format: { with: /^\w+$/ }
@jasonrudolph
jasonrudolph / about.md
Last active May 2, 2025 12:20
Programming Achievements: How to Level Up as a Developer
@RyanScottLewis
RyanScottLewis / rulebook_rewrite.rb
Created December 21, 2010 20:02
Rewrite of my RuleBook gem
module RuleBook
def RuleBook.add_rules(object, instance_or_class, rules)
instance_or_class = instance_or_class.to_s.downcase.strip.to_sym
raise(ArgumentError, "'instance_or_class' must equal :instance or :class") unless [:instance, :class].include?(instance_or_class)
raise(ArgumentError, "'rules' must be a Hash") unless rules.is_a?(Hash)
unless object.instance_variable_get(:@_rulebook_initiated) # Class instance variable. Not class variable. Not instance variable. Is confusing.
object.instance_variable_set(:@_rulebook_initiated, true)
object.instance_variable_set(:@_rulebook, {:instance=>{}, :class=>{}}) # @_rulebook is actually two rulebooks, instance and class
end