Created
August 21, 2025 12:33
-
-
Save enderahmetyurt/9901715aff837ecfa91c4cde9598ab5e to your computer and use it in GitHub Desktop.
Write a generator function `createLaundryItem()` that returns an object representing a laundry item. This object should have a method nextCycle() which, when called, advances the item through a series of laundry cycles in order: "soak", "wash", "rinse", "spin", and "dry". After the final cycle, subsequent calls to nextCycle() should return "done".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LaundryItem | |
CYCLES = %i[soak wash rinse spin dry].freeze | |
def initialize | |
@current_index = -1 | |
end | |
def next_cycle | |
if @current_index < CYCLES.size - 1 | |
@current_index += 1 | |
CYCLES[@current_index].to_s.capitalize | |
else | |
"Done" | |
end | |
end | |
end | |
item = LaundryItem.new | |
puts item.next_cycle | |
puts item.next_cycle | |
puts item.next_cycle | |
puts item.next_cycle | |
puts item.next_cycle | |
puts item.next_cycle | |
puts item.next_cycle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment