Last active
December 18, 2015 16:49
-
-
Save jwo/5814544 to your computer and use it in GitHub Desktop.
Step 2: better
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 :first_name, :last_name | |
def initialize(first_name, last_name) | |
@firstName = first_name | |
@lastName = last_name | |
end | |
def full_name | |
"#{first_name} #{last_name}" | |
end | |
def account | |
Account.for_user(self) | |
end | |
def active? | |
account.balance > 0 | |
end | |
end | |
class Account | |
def self.for_user(user) | |
new | |
end | |
def balance | |
[50, 150, 2500].sample | |
end | |
end | |
def users | |
[ | |
User.new("Frank", "Gleason"), | |
User.new("Bill", "Simmons"), | |
User.new("Sarah", "Coderson") | |
] | |
end | |
puts "----------User Account Balance Report ---------------------" | |
users.select{|user| user.active?}.each do |user| | |
puts user.full_name | |
puts user.account.balance | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment