From 8cbfcd2db4d342f550523cd60507c1c71bdf21a5 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 20 Sep 2021 08:31:19 +0200 Subject: [PATCH] Stuff --- prog2/quiz/beverage.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 prog2/quiz/beverage.rb diff --git a/prog2/quiz/beverage.rb b/prog2/quiz/beverage.rb new file mode 100644 index 0000000..8ecb7c7 --- /dev/null +++ b/prog2/quiz/beverage.rb @@ -0,0 +1,17 @@ +class Beverage + attr_accessor :name, :volume, :ingredients + def initialize(name, volume_in_ml, ingredients) + @name = name + @volume = volume_in_ml + @ingredients = ingredients + end + + def consume(amount_in_ml) + @volume -= amount_in_ml + if( @volume < 0 ) then @volume = 0 end + end + + def empty? + @volume <= 0 + end +end