1. 实例方法

实例方法(instance method)在类定义中声明,旨在供类的特定对象或“实例”(instance)使用,如下所示:

  1. class MyClass
  2. # declare instance method
  3. def instanceMethod
  4. puts( "This is an instance method" )
  5. end
  6. end
  7. # create object
  8. ob = MyClass.new
  9. # use instance method
  10. ob.instanceMethod