#!/usr/bin/ruby -w
# 定義類
class Box
# 構(gòu)造函數(shù)
def initialize(w,h)
@width, @height = w, h
end
# 訪問器方法
def printWidth
@width
end
def printHeight
@height
end
end
# 創(chuàng)建對(duì)象
box = Box.new(10, 20)
# 使用訪問器方法
x = box.printWidth()
y = box.printHeight()
puts "Width of the box is : #{x}"
puts "Height of the box is : #{y}"