Created
July 12, 2016 23:00
-
-
Save jonahgeorge/1dade89cab5f3996d802878b11b08183 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
class Connected; end | |
class Disconnected; end | |
class Connection(T); | |
def initialize | |
Connection(Disconnected).new | |
end | |
def connect | |
puts "Connected!" | |
Connection(Connected).new | |
end | |
def disconnect | |
puts "Disconnected!" | |
Connection(Disconnected).new | |
end | |
end | |
# class ConnectionDisconnected < Connection(Disconnected) | |
# def connect | |
# Connection(Connected).new | |
# end | |
# end | |
# | |
# class ConnectionConnected < Connection(Connected) | |
# def disconnect | |
# Connection(Disconnected).new | |
# end | |
# end | |
x = Connection(Disconnected).new # Connection<Disconnected> | |
# x.disconnect # compile-time error | |
x = x.connect # Connection<Connected> | |
# x.connect # compile-time error | |
x = x.disconnect # Connection<Disconnected> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment