Created
January 20, 2010 02:59
-
-
Save pedromtavares/281552 to your computer and use it in GitHub Desktop.
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 Remote | |
| def initialize(door) | |
| @door = door | |
| end | |
| def press_button | |
| puts "Pressing the remote control button..." | |
| if @door.is_open | |
| @door.close | |
| else | |
| @door.open | |
| sleep = Thread.new do | |
| sleep 2 | |
| @door.close | |
| end | |
| end | |
| while sleep.alive? | |
| sleep 0.1 | |
| end | |
| end | |
| end |
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
| require 'dog_door.rb' | |
| require 'remote.rb' | |
| door = DogDoor.new | |
| remote = Remote.new(door) | |
| puts "Fido barks to go outside..." | |
| remote.press_button | |
| puts "Fido has gone outside..." | |
| puts "Fido's all done..." | |
| puts "Fido's back inside" |
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 DogDoor | |
| attr_reader :is_open | |
| def initialize | |
| @is_open = false | |
| end | |
| def open | |
| puts "The dog door opens.\n\n" | |
| @is_open = true | |
| end | |
| def close | |
| puts "The dog door closes.\n\n" | |
| @is_open = false | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment