Skip to content

Instantly share code, notes, and snippets.

@ravinggenius
Last active August 10, 2016 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravinggenius/dd9f6e08fdcbf9a50e7f5907f56be7ec to your computer and use it in GitHub Desktop.
Save ravinggenius/dd9f6e08fdcbf9a50e7f5907f56be7ec to your computer and use it in GitHub Desktop.
Exploration of allowed mutations in Rip

Mutations to the currently-initializing object will be allowed in Rip.

Notes

  • Methods defined at the class level are typically written as a simple reference assignment.
  • @ inside a class refers to the class' prototype property. Properties defined on this object become instance methods.
  • @ inside a method refers to the method's receiver. (self refers to the method itself.)
# library...
Connection = class {
@.initialize = (adapter, host, port, username, password) -> {
@.adapter = adapter
@.host = host
@.port = port
@.username = username
@.password = password
}
}
# usage...
db = Connection.new(:postgres, "www.example.com", 1234, :root, "")
# library...
Connection = class {
@.initialize = (builder) -> {
builder(@)
@.indirect = true
}
}
# usage...
db = Connection.new((@@) -> {
@@.adapter = :postgres
@@.host = "www.example.com"
@@.port = 1234
@@.username = :root
@@.password = ""
})
# library...
Connection = class {
@.initialize = (builder) -> {
builder(@)
}
build = (builder) -> {
@.new((@@) -> {
builder(@@)
@@.very_indirect = true
})
}
}
# usage...
db = Connection.build((@@) -> {
@@.adapter = :postgres
@@.host = "www.example.com"
@@.port = 1234
@@.username = :root
@@.password = ""
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment