Skip to content

Instantly share code, notes, and snippets.

@fredreichbier
Created August 15, 2010 15:18
Show Gist options
  • Select an option

  • Save fredreichbier/525596 to your computer and use it in GitHub Desktop.

Select an option

Save fredreichbier/525596 to your computer and use it in GitHub Desktop.
import structs/[ArrayList,HashMap]
A: class {
hello: String
init: func (=hello) {}
}
B: class extends A {
init: super func
}
globalA := A new("THE WHOLE WORLD")
test: func (value: Object) {
match(value) {
case globalA => {
"Global A! %s" format(value as A hello) println()
}
case b: B => {
"B! %s" format(b hello) println()
}
case a: A => {
"A! %s" format(a hello) println()
}
}
}
testGeneric: func <T> (value: T) {
match(value) {
case a: Int => {
"Int! %d" format(a) println()
}
case s: String => "String! %s" format(s) println()
case => {
"No idea" println()
}
}
}
main: func {
test(A new("World!"))
test(B new("Borld!"))
test(globalA)
testGeneric(123)
testGeneric("huhu")
testGeneric(false)
}
@nddrylliog
Copy link
Copy Markdown

Awesome! It could be used in many places in rock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment