Skip to content

Instantly share code, notes, and snippets.

@cbergau
Created May 10, 2014 16:58
Show Gist options
  • Save cbergau/402a4c5b84aecfea9877 to your computer and use it in GitHub Desktop.
Save cbergau/402a4c5b84aecfea9877 to your computer and use it in GitHub Desktop.
My very first ruby script
require "YAML"
# My very first Ruby code ever.
class LoginInteractor
attr_accessor :presenter
def initialize(presenter)
@presenter = presenter
end
def execute(request)
loginResponse = LoginResponse.new
if request.username == "Christian" && request.password == "Password"
loginResponse.userid = 5
loginResponse.success = true
else
loginResponse.userid = nil
loginResponse.success = false
end
presenter.response = loginResponse
end
end
class LoginRequest
attr_accessor :username
attr_accessor :password
end
class LoginResponse
attr_accessor :userid
attr_accessor :success
end
class LoginPresenter
attr_accessor :response
end
loginPresenter = LoginPresenter.new
loginRequest = LoginRequest.new
loginRequest.username = "Christian"
loginRequest.password = "P4ssw0rd"
loginInteractor = LoginInteractor.new(loginPresenter)
loginInteractor.execute(loginRequest)
puts YAML::dump(loginPresenter)
loginRequest.password = "Password"
loginInteractor.execute(loginRequest)
puts YAML::dump(loginPresenter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment