Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
minitest (5.10.3) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
minitest | ||
|
||
BUNDLED WITH | ||
1.11.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
require 'bigdecimal' | ||
require 'bigdecimal/util' | ||
|
||
class Product | ||
attr_accessor :name, :price | ||
|
||
def initialize name, price | ||
@name = name | ||
@price = price | ||
@price = price.to_d | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pmkaboo
Author
Owner
|
||
end | ||
|
||
def to_s | ||
# regex truncate to always display two decimals | ||
name + ', ' + (price.to_s('F') + '0')[/.*\..{2}/] | ||
This comment has been minimized.
Sorry, something went wrong.
martincik
Collaborator
|
||
end | ||
|
||
end |
What happens if I put as a price string or some other type that is not convertible to Decimal? (Imaging that someone makes mistake and puts there not number.)