ArgumentError when calling function

1

I'm trying to run this code below:

class ProdutItem

  attr_reader :price_unit, :x_item, :price_promo

  def initialize(price_unit: , x_item: 1, price_promo: price_unit)
    @price_unit = price_unit
    @x_item = x_item
    @price_promo = price_promo
  end

  def price_qtde(units)
    units_promo = units / @x_item
    units_eo = units % @x_item
    @price_promo * units_promo + @price_unit * units_eo
  end

end

rules = ProdutItem.new(price_unit: 50, x_item: 3, price_promo: 130)
puts rules.price_qtde

But this error is showing below:

Checkout.rb:11:in 'price_qtde': wrong number of arguments (given 0, expected 1) (ArgumentError)
    
asked by anonymous 15.12.2017 / 19:28

1 answer

1

The function price_qtde is given a parameter ( units ), but when calling this function in the last line of your code, it is not informing any argument.

If the value of units should be 2 , then do:

puts rules.price_qtde 2

or

puts rules.price_qtde(2)
    
15.12.2017 / 19:31