[ next ] [ prev ] [ contents ] [ up to Appendix A -- What is Object Oriented? ] Invitation To Ruby

Dice in Ruby (cont)

Some code that uses a dice object

  1: def use_dice(d)
  2:   d.toss
  3:   puts "The top of the die is #{d.top}"
  4: end

  • [1-4] The use_dice function will toss a dice object and report the new top side.


Does use_dice care what kind of dice object it is using?



[ next ] [ prev ] [ contents ] [ up to Appendix A -- What is Object Oriented? ] Copyright 2002 by Jim Weirich.
All rights reserved.