Skip to content

Instantly share code, notes, and snippets.

@jwo
Last active December 18, 2015 16:49
Show Gist options
  • Save jwo/5814544 to your computer and use it in GitHub Desktop.
Save jwo/5814544 to your computer and use it in GitHub Desktop.
Step 2: better
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