Skip to content

Instantly share code, notes, and snippets.

@hypomodern
Created May 14, 2010 03:52
Show Gist options
  • Save hypomodern/400792 to your computer and use it in GitHub Desktop.
Save hypomodern/400792 to your computer and use it in GitHub Desktop.
# bare Prototypes begin with a Capital Letter, and you usually clone Object:
Cube := Object clone
# := creates a new 'slot' on the receiver and sets that slot to the value of the right-hand side:
Cube sides := 6
# Io has simple message-passing, no operator used: 'Receiver message'
Cube sides # ===> 6
# to def a method rather than a raw property, use the "method" message:
Cube description := method("A Plain Platonic Solid" print)
# methods are called just the same:
Cube description # => A Plain Platonic Solid
# 'inheritance' is via explicit clone.
D6 := Cube clone
# check properties and methods with "slotNames"...
D6 slotNames # => list(type) waitaminute!
# ...but method searching is done up the prototype chain, so there are no slotNames here, yet...
D6 sides # => 6
# to create an instance, use a lower-cased variable name when cloning
D6 description := method("A six-sided 3-D shape with pips on the sides")
fancy_d6 = D6 clone do(
description := "A Gold-plated Wonder of a die"
)
# use "proto" to get the next object up the chain:
fancy_d6 proto proto # => Cube...
# use "perform" to send a Sequence (=String) as a message
fancy_d6 perform("sides") # is the same as d6 sides, but now we know how to metaprogram a bit!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment