Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. class Fruit
  2. attr_accessor :color, :type
  3. attr_reader :total_price
  4. def initialize(color, type, amount, unit_price)
  5. @color = color
  6. @type = type
  7. @total_price = amount * unit_price
  8. end
  9.  
  10. def to_s
  11. "Color: #{self.color}; Type: #{self.type}; Total price: #{self.total_price}"
  12. end
  13. end
  14.  
  15. pear = Fruit.new 'green', :pear, 3, 10
  16. puts pear
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement