[
next
] [
prev
] [
contents
] [
up to Appendix A -- What is Object Oriented?
]
Invitation To Ruby
Ruby and Object Orientation
Ruby is 100% object oriented.
Everything is Ruby is an object, even numbers!
1.times {...} sends the
times
message to the
Integer
object
1
.
Nearly all computation in Ruby is performed by sending messages.
1+2
is shorthand for
1.+(2)
I.e. send the message "+" to
1
with an argument of
2
.
BTW, there are no functions ... just methods
Top level function are really methods of a main root object
Really!
Try evaluating self in a top level function.
Classes are Objects in Ruby
StandardDice
is just a constant bound to a class object.
To create a new object, just send the
new
message to a class object and it will construct and object of its type.
I.e. sending
new
to
StandardDice
will create an instance (object) of the
StandardDice
class.
[
next
] [
prev
] [
contents
] [
up to Appendix A -- What is Object Oriented?
]
Copyright 2002 by Jim Weirich.
All rights reserved.