Created
May 15, 2014 22:23
-
-
Save DiegoSalazar/dc48f1447b3aed6b645e to your computer and use it in GitHub Desktop.
ESAAS HW0 Part 3
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 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