Created
February 2, 2016 10:56
-
-
Save domgetter/7cfed4e1938de458e153 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
class User | |
attr_reader :hashed_pass | |
def initalize | |
@hashed_pass = "" | |
end | |
def change_profile_pic(other_pic) | |
@profile_pic = other_pic | |
end | |
end | |
class Authorization | |
def initialize(value) | |
@value = value | |
end | |
def authorize(credentials = nil) | |
# @value[:allowed] = credentials.valid? | |
@value[:allowed] = true | |
self | |
end | |
def self.unit(value) | |
new({allowed: false, value: value}) | |
end | |
def map | |
yield @value[:value] if @value[:allowed] | |
self | |
end | |
end | |
user = User.new | |
auth_user = Authorization.unit(user) | |
auth_user.map {|user| user.change_profile_pic("dickpiclol.jpg")} | |
# #<Authorization:0x00000002da4cb8 @value={:allowed=>false, :value=>#<User:0x00000002dfec18>}> | |
credentials = {user: user, hashed_pass: user.hashed_pass} | |
auth_user.authorize(credentials).map {|user| user.change_profile_pic "yosemite.jpg" } | |
# #<Authorization:0x00000002da4cb8 @value={:allowed=>true, :value=>#<User:0x00000002dfec18 @profile_pic="yosemite.jpg">}> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment