Skip to content

Instantly share code, notes, and snippets.

@DiegoSalazar
Created May 15, 2014 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DiegoSalazar/dc48f1447b3aed6b645e to your computer and use it in GitHub Desktop.
Save DiegoSalazar/dc48f1447b3aed6b645e to your computer and use it in GitHub Desktop.
ESAAS HW0 Part 3
class BookInStock
# declare setters and getters
attr_accessor :isbn, :price
def initialize(isbn, price)
# checking for empty string or price is greater 0, raises exception
raise ArgumentError if isbn.strip.empty? || price <= 0
@isbn, @price = isbn, price
end
def price_as_string
# using a formatting string to convert to money representation
sprintf '$%.2f', price
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment