Skip to content

Instantly share code, notes, and snippets.

@jonahgeorge
Created July 12, 2016 23:00
Show Gist options
  • Save jonahgeorge/1dade89cab5f3996d802878b11b08183 to your computer and use it in GitHub Desktop.
Save jonahgeorge/1dade89cab5f3996d802878b11b08183 to your computer and use it in GitHub Desktop.
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