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 StandardCarBuilder | |
| def build | |
| car = '' | |
| # 1. build car frame | |
| car << "This is a standard car\n" | |
| # 2. add an engine | |
| car << " with an engine\n" | |
| # 3. add front wheels | |
| car << " with two front wheels\n" | |
| # 4. add back wheels |
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 OreoCheesecake | |
| def make_crust | |
| puts 'making OreoCheesecake curst' | |
| end | |
| def add_layers | |
| puts 'making OreoCheesecake layers' | |
| end | |
| def bake |
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 ActorProxy | |
| attr_reader :schedule, :preference, :actor | |
| def initialize(schedule, preference, actor) | |
| @schedule = schedule | |
| @preference = preference | |
| @actor = actor | |
| end | |
| def handle(request) |
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 Lock | |
| attr_reader :cleared_state, :entered_pin_one_state, | |
| :entered_pin_two_state, :entered_pin_three_state, | |
| :unlocked_state, :entered_wrong_pin_state | |
| attr_accessor :state | |
| def initialize | |
| @cleared_state = ClearedState.new(self) | |
| @entered_pin_one_state = EnteredPinOneState.new(self) | |
| @entered_pin_two_state = EnteredPinTwoState.new(self) |
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 EnteredPinThreeState | |
| attr_reader :lock, :state_name | |
| def initialize(lock) | |
| @lock = lock | |
| @state_name = 'Entered Pin Three State' | |
| end | |
| def dial_to(number) | |
| lock.state = lock.entered_wrong_pin_state |
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 UnlockedState | |
| attr_reader :lock, :state_name | |
| def initialize(lock) | |
| @lock = lock | |
| @state_name = 'Unlocked State' | |
| end | |
| def dial_to(number) | |
| puts 'The lock is unlocked. Dial does nothing.' |
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 EnteredWrongPinState | |
| attr_reader :lock, :state_name | |
| def initialize(lock) | |
| @lock = lock | |
| @state_name = 'Entered Wrong Pin State' | |
| end | |
| def dial_to(number) | |
| puts "The lock is in #{state_name}. Dial does nothing." |
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 EnteredPinTwoState | |
| attr_reader :lock, :state_name | |
| def initialize(lock) | |
| @lock = lock | |
| @state_name = 'Entered Pin Two State' | |
| end | |
| def dial_to(number) | |
| if number == 9 |
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 EnteredPinOneState | |
| attr_reader :lock, :state_name | |
| def initialize(lock) | |
| @lock = lock | |
| @state_name = 'Entered Pin One State' | |
| end | |
| def dial_to(number) | |
| if number == 8 |
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 ClearedState | |
| attr_reader :lock, :state_name | |
| def initialize(lock) | |
| @lock = lock | |
| @state_name = 'Cleared State' | |
| end | |
| def dial_to(number) | |
| if number == 7 |