June 2017
Beginner
330 pages
7h 30m
English
Here we have an Invoice class that seems to be relatively straightforward:
Following is the implementation of the Invoice class:
class Invoice def initialize(customer:, state:, total:) @customer = customer @state = state @total = total end def details "Customer: #{@customer}, Total: #{@total}" end def sales_tax case @state when 'AZ' then 5.5 when 'TX' then 3.2 when 'CA' then 8.7 end end def email_invoice puts "Emailing invoice..." puts details endendinvoice = Invoice.new(customer: "Google", state: "AZ", total: 100)puts invoice.sales_taxinvoice.email_invoice
When we run this code, everything works fine and ...
Read now
Unlock full access