Created
September 25, 2009 19:24
-
-
Save dekellum/193768 to your computer and use it in GitHub Desktop.
This file contains 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
# Started with something like this | |
class GoKart | |
def initialize( strategy = nil ) | |
@strategy = strategy | |
end | |
def drive | |
if @strategy == :reverse | |
puts "Reverse" | |
else | |
puts "Forward" | |
end | |
end | |
def stop | |
puts "Stop" | |
end | |
end | |
# And have external consumer doing this: | |
k = GoKart.new() | |
k.drive | |
k.stop | |
k = GoKart.new( :reverse ) | |
k.drive | |
k.stop | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment