Last active
August 20, 2016 19:43
-
-
Save jordanhudgens/9ecceb91b474cebc61e78969465db0ee to your computer and use it in GitHub Desktop.
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
# Violation | |
# require 'date' | |
# class User | |
# attr_accessor :settings, :email | |
# def initialize(email:) | |
# @email = email | |
# end | |
# end | |
# class AdminUser < User | |
# end | |
# user = User.new(email: "user@test.com") | |
# user.settings = {level: "Low Security", status: "Live", signed_in: Date.today} | |
# admin = AdminUser.new(email: "admin@test.com") | |
# admin.settings = ["Editor", "VIP", Date.today] | |
# @user_database = [user, admin] | |
# def signed_in_today? | |
# @user_database.each do |user| | |
# if user.settings[:signed_in] == Date.today | |
# puts "#{user.email} signed in today" | |
# end | |
# end | |
# end | |
# signed_in_today? | |
# Fixed code | |
require 'date' | |
require 'ostruct' | |
class User | |
attr_accessor :email | |
def initialize(email:) | |
@email = email | |
end | |
def set_settings(level:, status:, signed_in:) | |
@settings = OpenStruct.new(level: level, status: status, signed_in: signed_in) | |
end | |
def get_settings | |
@settings | |
end | |
end | |
class AdminUser < User | |
end | |
user = User.new(email: "user@test.com") | |
user.set_settings(level: "Low Security", status: "Live", signed_in: Date.today) | |
admin = AdminUser.new(email: "admin@test.com") | |
admin.set_settings(level: "Editor", status: "VIP", signed_in: Date.today) | |
@user_database = [user, admin] | |
def signed_in_today? | |
@user_database.each do |user| | |
if user.get_settings.signed_in == Date.today | |
puts "#{user.email} signed in today" | |
end | |
end | |
end | |
signed_in_today? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment