[ next ] [ prev ] [ contents ] [ skip to Dice in Ruby (cont) ] [ up to Appendix A -- What is Object Oriented? ] Invitation To Ruby

Sending an Object a Message

We can now use our Dice object by sending it messages.

  1: d = StandardDice.new
  2: d.toss
  3: puts "Top of die is #{d.top}"

  • [1] Magic incantation to create a StandardDice object
  • [2] Send the toss message. The object selects a new top value.
  • [3] Send the top message. Returns the current value of @top (5, or 3, etc)


[ next ] [ prev ] [ contents ] [ skip to Dice in Ruby (cont) ] [ up to Appendix A -- What is Object Oriented? ] Copyright 2002 by Jim Weirich.
All rights reserved.