View pacman-singleton-usage.rb
# move up the singleton instance
Pacman.instance.move_up
# the same instance will move right
Pacman.instance.move_right
# the same instance will move down
Pacman.instance.move_down
View pacman-singleton.rb
class Pacman
def self.get_instance
# instantiate the singleton instance if it is not existing yet.
if @instance.nil?
@instance = Pacman.new
end
@instance
end
View rhcc-correct-password-function.rb
def correct_password? user, password
encrypted_password = BCrypt::Password.new password
user.encrypted_password == encrypted_password
end
View rhcc-email-format-function.rb
VALID_EMAIL_REGEX = /\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
def valid_email? email
email =~ VALID_EMAIL_REGEX
end
View rhcc-correct-password.rb
encrypted_password = BCrypt::Password.new password
if user.encrypted_password == encrypted_password
View rhcc-email-format.rb
email !=~ /\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
View rhcc-authenticate-refactored.rb
VALID_EMAIL_REGEX = /\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
def authenticate email, password
user = User.find_by_email email
if password.present? && valid_email?(email) && user.present? && correct_password?(user, password)
user
else
false
end
View rhcc-authenticate.rb
def authenticate email, password
user = User.find_by_email email
if password.nil? || email !=~ /\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i || user.nil?
return false
end
encrypted_password = BCrypt::Password.new password
if user.encrypted_password == encrypted_password
user
View business-models.md

Business Models

Advertising

Models Examples
Display ads Yahoo!
Search ads Google