Skip to content

Instantly share code, notes, and snippets.

@timcase
Created November 9, 2018 16:53
Show Gist options
  • Save timcase/4186ec74bfc0d01ec5f438c636578e0d to your computer and use it in GitHub Desktop.
Save timcase/4186ec74bfc0d01ec5f438c636578e0d to your computer and use it in GitHub Desktop.
def print_bill
outstanding = 0.0
#print banner
puts "*************************"
puts "******Customer Owes******"
puts "*************************"
# calculate outstanding
@orders.each do |order|
oustanding += order.amount
end
#print details
puts "name: #{@name}"
puts "amount: #{outstanding}"
end
def calculate_outstanding
@order.inject(0.0){ |result, order| result + order.amount] }
end
def print_banner
puts "*************************"
puts "******Customer Owes******"
puts "*************************"
end
def print_outstanding(outstanding)
puts "name: #{@name}"
puts "amount: #{outstanding}"
end
def print_bill
print_banner
outstanding = calculate_oustanding
print_outstanding(outstanding)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment