0
class ProdutItem
attr_reader :item, :price_unit, :qtde
def initialize(item, price_unit, qtde)
@item = item
@price_unit = price_unit
@qtde = qtde
end
def calc_qtde
(price_unit * qtde)
end
end
prod = ProdutItem.new("A", 0.50, 3)
puts prod.calc_qtde
class CalcDiscount
attr_reader :discount
def initialize(discount)
@discount = discount
end
def calc_desc
(price_unit * qtde) - discount
end
end
desc = CalcDiscount.new(0.20)
puts desc.calc_desc
When I run this my above code returns the following error msg:
teste_04.Rb:29:in
calc_desc': undefined local variable or method
price_unit' for # (Nameerror) from teste_04.Rb:34:in `'
Eu nao consigo identificar o erro. Alguem poderia me ajudar?
I believe you are not creating the variable : "calc_desc"
– Bruno
price_unit
does not exist within the classCalcDiscount
only in theProdutItem
and if it exists it must be accessed with@
– Isac
Isac, even add the price_unit, continues with error: teste_04.Rb:24:in `initialize': Wrong number of Arguments (Given 1, expected 2) (Argumenterror)
– Cintia B