I have an Item
class, and I initialized five variables. I am trying to match the output in my terminal to the value of the expected_summary
. I am calling Item.summary
in the following code:
class Item
attr_reader :name, :description, :manufacturer, :price, :summary
def initialize (name, manufacturer, price, description=nil, summary=nil)
@name = name
@manufacturer = manufacturer
@price = price
@description = description
if description
@summary = "Name: #{name}
Description: #{description}
Manufacturer: #{manufacturer}
Price: $#{price}"
else
@summary = "Name: #{name}
Manufacturer: #{manufacturer}
Price: $#{price}"
end
end
end
#expected_summary = %q(Name: Spy Notebook
#Manufacturer: Spys-R-Us
#Price: $10.50)
item = Item.new("Spy Notebook", "Spys-R-Us", 10.50)
puts item.summary
When I pass a number 10.50
as the price
argument, it returns as 10.5
. I cannot figure out why. Why does Ruby read 10.50
as 10.5
? Is there a way to correct this?