Argue when calling function

Asked

Viewed 43 times

1

I’m trying to run my 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

However this error is appearing below:

Checkout.rb:11:in `price_qtde': wrong number of arguments (given 0, expected 1) (ArgumentError)

1 answer

1


The function price_qtde receives a parameter (units), but by calling this function in the last line of your code, you are not giving any argument.

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

puts rules.price_qtde 2

or

puts rules.price_qtde(2)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.